public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out FeatureLevel featureLevel, out ID3D11DeviceContext immediateContext) { var result = D3D11CreateDevice(adapter, driverType, IntPtr.Zero, (int)flags, featureLevels, (featureLevels != null) ? featureLevels.Length : 0, SdkVersion, out device, out featureLevel, out immediateContext); if (result.Failure) { return(result); } if (immediateContext != null) { device.AddRef(); device.ImmediateContext__ = immediateContext; immediateContext.Device__ = device; } return(result); }
public unsafe static Result D3D11On12CreateDevice( IUnknown d3d12Device, DeviceCreationFlags flags, FeatureLevel[] featureLevels, IUnknown[] commandQueues, int nodeMask, out ID3D11Device device, out ID3D11DeviceContext immediateContext, out FeatureLevel chosenFeatureLevel) { var result = D3D11On12CreateDevice(d3d12Device, flags, featureLevels, featureLevels.Length, commandQueues, commandQueues.Length, nodeMask, out device, out immediateContext, out chosenFeatureLevel); if (result.Failure) { return(result); } if (immediateContext != null) { device.AddRef(); device.ImmediateContext__ = immediateContext; immediateContext.Device__ = device; } return(result); }
/// <summary> /// Gets the highest supported hardware feature level of the primary adapter. /// </summary> /// <param name="adapter">The <see cref="IDXGIAdapter"/>.</param> /// <returns>The highest supported hardware feature level.</returns> public static FeatureLevel GetSupportedFeatureLevel(IDXGIAdapter adapter) { var featureLevel = FeatureLevel.Level_9_1; ID3D11Device device = null; ID3D11DeviceContext context = null; try { D3D11CreateDevice( adapter, DriverType.Unknown, IntPtr.Zero, 0, null, 0, SdkVersion, out device, out featureLevel, out context); } finally { context?.Dispose(); device?.Dispose(); } return(featureLevel); }
private static Result RawD3D11CreateDeviceNoContext( IntPtr adapterPtr, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device?device, out FeatureLevel featureLevel) { unsafe { device = default; fixed(void *featureLevelsPtr = &featureLevels[0]) fixed(void *featureLevelPtr = &featureLevel) { IntPtr devicePtr = IntPtr.Zero; Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? featureLevelsPtr : null, featureLevels?.Length ?? 0, SdkVersion, &devicePtr, featureLevelPtr, null); if (result.Success && devicePtr != IntPtr.Zero) { device = new ID3D11Device(devicePtr); } return(result); } } }
public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device) { return(D3D11CreateDevice(adapter, driverType, flags, featureLevels, out device, out var featureLevel, out var immediateContext)); }
public static Result D3D11CreateDevice(IntPtr adapterPtr, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device) { return(RawD3D11CreateDeviceNoContext( adapterPtr, driverType, flags, featureLevels, out device, out _)); }
public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device) { return(RawD3D11CreateDeviceNoContext( adapter != null ? adapter.NativePointer : IntPtr.Zero, driverType, flags, featureLevels, out device, out _)); }
private void ReleaseDevice() { if (Device__ != null) { // Only call Dispose() when it is created by accessing ID3D11DeviceChild.Device. if (!shouldNotDisposeDevice) { Device__.Dispose(); Device__ = null; } } }
public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device) { ID3D11DeviceContext context = null; try { return(D3D11CreateDevice(adapter, driverType, flags, featureLevels, out device, out var featureLevel, out context)); } finally { context?.Dispose(); } }
private static Result RawD3D11CreateDeviceNoContext( IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out FeatureLevel featureLevel) { unsafe { device = default; var adapterPtr = CppObject.ToCallbackPtr <IDXGIAdapter>(adapter); fixed(void *featureLevelsPtr = &featureLevels[0]) fixed(void *featureLevelPtr = &featureLevel) { var devicePtr = IntPtr.Zero; Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? featureLevelsPtr : null, featureLevels?.Length ?? 0, SdkVersion, &devicePtr, featureLevelPtr, null); if (result.Success && devicePtr != IntPtr.Zero) { device = new ID3D11Device(devicePtr); } GC.KeepAlive(adapter); return(result); } } }
/// <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(IDXGIAdapter adapter, FeatureLevel featureLevel) { ID3D11Device device = null; ID3D11DeviceContext context = null; try { var result = D3D11CreateDevice( adapter, DriverType.Unknown, IntPtr.Zero, 0, new[] { featureLevel }, 1, SdkVersion, out device, out var outputLevel, out context); return(result.Success && outputLevel == featureLevel); } finally { context?.Dispose(); device?.Dispose(); } }
public static Result D3D11CreateDevice(IntPtr adapterPtr, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out ID3D11DeviceContext immediateContext) { return(D3D11CreateDevice(adapterPtr, driverType, flags, featureLevels, out device, out _, out immediateContext)); }