private ScratchImage convertBC7(ScratchImage image) { SharpDX.DXGI.Factory1 factory = new SharpDX.DXGI.Factory1(); SharpDX.DXGI.Adapter adapter = factory.GetAdapter(0); Device device = new Device(adapter); return(image.Compress(device.NativePointer, DXGI_FORMAT.BC7_UNORM, TEX_COMPRESS_FLAGS.DEFAULT, 0.5f)); }
static void Main() { var renderForm = new RenderForm(""); SharpDX.DXGI.Factory f = new SharpDX.DXGI.Factory(); SharpDX.DXGI.Adapter a = f.GetAdapter(1); SharpDX.Direct3D11.Device d = new Device(a, DeviceCreationFlags.VideoSupport | DeviceCreationFlags.BgraSupport); SharpDX.Direct3D11.Device2 d2 = d.QueryInterface <SharpDX.Direct3D11.Device2>(); //d.Dispose();*/ /* var device = new RenderDevice(, 1); * RenderContext context = new RenderContext(device); * * var d = device.Device;*/ var multithread = d.QueryInterface <SharpDX.Direct3D.DeviceMultithread>(); multithread.SetMultithreadProtected(true); // Create a DXGI Device Manager var dxgiDeviceManager = new SharpDX.MediaFoundation.DXGIDeviceManager(); dxgiDeviceManager.ResetDevice(d); VideoDevice vd = d.QueryInterface <VideoDevice>(); //vd.VideoDecoderProfileCount /*VideoDecoderDescription desc = new VideoDecoderDescription() * { * * }*/ VideoContext ctx = d.ImmediateContext.QueryInterface <VideoContext>(); /*var swapChain = new DX11SwapChain(device, renderForm.Handle); * * /*var dx = new VideoDecoderDescription() * { * * }*/ /*int i = vd.VideoDecoderProfileCount; * * renderForm.ResizeEnd += (s, e) => swapChain.Resize(); * * RenderLoop.Run(renderForm, () => * { * context.Context.ClearRenderTargetView(swapChain.RenderView, new SharpDX.Color4(1, 1, 1, 1)); * * swapChain.Present(1, SharpDX.DXGI.PresentFlags.None); * });*/ }
public Direct2DCanvas() { int width = 1024; int height = 1024; SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device( SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport); // Query the default device for the supported device and context interfaces. var device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1> (); // Query for the adapter and more advanced DXGI objects. SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface <SharpDX.DXGI.Device2> (); SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter; SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent <SharpDX.DXGI.Factory2> (); var swapChainDescription = new SharpDX.DXGI.SwapChainDescription1 { Width = width, Height = height, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.Stretch, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, Flags = SharpDX.DXGI.SwapChainFlags.None, }; swapChainDescription.SampleDescription.Count = 1; swapChainDescription.SampleDescription.Quality = 0; swapChain = dxgiFactory2.CreateSwapChainForComposition(dxgiDevice2, ref swapChainDescription, null); swapChain.BackgroundColor = new Color4(1, 0, 0, 0); var native = SharpDX.ComObject.QueryInterface <SharpDX.DXGI.ISwapChainBackgroundPanelNative> (this); native.SwapChain = swapChain; g = new Direct2DGraphics(swapChain); _drawTimer = new WindowsDrawTimer { Continuous = true, ShouldDrawFunc = () => Content != null && ActualWidth > 0 && ActualHeight > 0, DrawFunc = Draw, }; Unloaded += HandleUnloaded; Loaded += HandleLoaded; LayoutUpdated += HandleLayoutUpdated; }
private void Initialize(IntPtr devicePointer) { FeatureLevel[] levels = new FeatureLevel[] { #if DIRECTX11_1 FeatureLevel.Level_11_1, #endif FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3 }; Device dev; if (devicePointer != IntPtr.Zero) { dev = new SharpDX.Direct3D11.Device(devicePointer); } else if (adapterindex > 0) { SharpDX.DXGI.Factory f = new SharpDX.DXGI.Factory1(); SharpDX.DXGI.Adapter a = f.GetAdapter(adapterindex); dev = new Device(a, this.creationflags, levels); f.Dispose(); a.Dispose(); } else { dev = new Device(DriverType.Hardware, this.creationflags, levels); } #if DIRECTX11_1 this.Device = dev.QueryInterface <DirectXDevice>(); Marshal.Release(this.Device.NativePointer); #else this.Device = dev; #endif DXGIDevice dxgidevice = this.Device.QueryInterface <DXGIDevice>(); Marshal.Release(this.Device.NativePointer); this.Adapter = dxgidevice.Adapter.QueryInterface <DXGIAdapter>(); Marshal.Release(dxgidevice.Adapter.NativePointer); this.Factory = this.Adapter.GetParent <DXGIFactory>(); Marshal.Release(this.Adapter.NativePointer); this.OnLoad(); }
/// <summary> /// <p>Creates a device that represents the display adapter.</p> /// </summary> /// <param name="adapterRef"><dd> <p>A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <p><strong>Note</strong>??Do not mix the use of DXGI 1.0 (<strong><see cref="SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref="SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref="SharpDX.DXGI.Factory"/></strong> or <strong><see cref="SharpDX.DXGI.Factory1"/></strong>, but not both in an application.</p> </dd></param> /// <param name="driverType"><dd> <p>The <strong><see cref="SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create.</p> </dd></param> /// <param name="software"><dd> <p>A handle to a DLL that implements a software rasterizer. If <em>DriverType</em> is <em><see cref="SharpDX.Direct3D.DriverType.Software"/></em>, <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle.</p> </dd></param> /// <param name="flags"><dd> <p>The runtime layers to enable (see <strong><see cref="SharpDX.Direct3D11.DeviceCreationFlags"/></strong>); values can be bitwise OR'd together.</p> </dd></param> /// <param name="featureLevelsRef"><dd> <p>A reference to an array of <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong>s, which determine the order of feature levels to attempt to create. If <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function uses the following array of feature levels:</p> <pre> { <see cref="SharpDX.Direct3D.FeatureLevel.Level_11_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_1"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_3"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_2"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_1"/>,}; </pre> <p><strong>Note</strong>??If the Direct3D 11.1 runtime is present on the computer and <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function won't create a <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> device. To create a <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> device, you must explicitly provide a <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> array that includes <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong>. If you provide a <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> array that contains <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.</p> </dd></param> /// <param name="featureLevels"><dd> <p>The number of elements in <em>pFeatureLevels</em>.</p> </dd></param> /// <param name="sDKVersion"><dd> <p>The SDK version; use <em><see cref="SharpDX.Direct3D11.D3D11.SdkVersion"/></em>.</p> </dd></param> /// <param name="deviceOut"><dd> <p>Returns the address of a reference to an <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object that represents the device created.</p> </dd></param> /// <param name="featureLevelRef"><dd> <p>If successful, returns the first <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> from the <em>pFeatureLevels</em> array which succeeded. Otherwise, returns 0.</p> </dd></param> /// <param name="immediateContextOut"><dd> <p>Returns the address of a reference to an <strong><see cref="SharpDX.Direct3D11.DeviceContext"/></strong> object that represents the device context.</p> </dd></param> /// <returns><p>This method can return one of the Direct3D 11 Return Codes.</p><p>This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value.</p></returns> /// <remarks> /// <p>This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644).</p><p>To create a Direct3D 11.1 device (<strong><see cref="SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device1"/></strong> interface. /// </p><p>To create a Direct3D 11.2 device (<strong><see cref="SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device2"/></strong> interface. /// </p><p>Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking at pFeatureLevel without creating a device.</p><p>For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use <strong>D3D11CreateDeviceAndSwapChain</strong>.</p><p>If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Unknown"/> value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value, <strong><see cref="SharpDX.Direct3D11.D3D11.CreateDevice"/></strong> returns an <strong><see cref="SharpDX.Result"/></strong> of E_INVALIDARG.</p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p>In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could mismatch what the adapter was.</p> <p>In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains the other inputs to be:</p> <ul> <li><em>DriverType</em> must be <see cref="SharpDX.Direct3D.DriverType.Unknown"/></li> <li><em>Software</em> must be <strong><c>null</c></strong>.</li> </ul> <p>On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to <see cref="SharpDX.Direct3D.DriverType.Unknown"/>; it can be set to either:</p> <ul> <li>If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Software"/>, <em>Software</em> cannot be <strong><c>null</c></strong>.</li> <li>If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Hardware"/>, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p><strong>Windows?Phone?8:</strong> This API is supported.</p><p><strong>Windows Phone 8.1:</strong> This API is supported.</p> /// </remarks> /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='D3D11CreateDevice']/*"/> /// <msdn-id>ff476082</msdn-id> /// <unmanaged>HRESULT D3D11CreateDevice([In, Optional] IDXGIAdapter* pAdapter,[In] D3D_DRIVER_TYPE DriverType,[In] HINSTANCE Software,[In] D3D11_CREATE_DEVICE_FLAG Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[Out, Fast] ID3D11Device** ppDevice,[Out, Optional] D3D_FEATURE_LEVEL* pFeatureLevel,[Out, Optional] ID3D11DeviceContext** ppImmediateContext)</unmanaged> /// <unmanaged-short>D3D11CreateDevice</unmanaged-short> public static SharpDX.Result CreateDevice(SharpDX.DXGI.Adapter adapterRef, SharpDX.Direct3D.DriverType driverType, System.IntPtr software, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, int featureLevels, int sDKVersion, SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D.FeatureLevel featureLevelRef, out SharpDX.Direct3D11.DeviceContext immediateContextOut) { unsafe { SharpDX.Direct3D.FeatureLevel[] featureLevelsRef__ = featureLevelsRef; IntPtr deviceOut_ = IntPtr.Zero; IntPtr immediateContextOut_ = IntPtr.Zero; SharpDX.Result __result__; fixed(void *featureLevelsRef_ = featureLevelsRef__) fixed(void *featureLevelRef_ = &featureLevelRef) __result__ = D3D11CreateDevice_((void *)((adapterRef == null)?IntPtr.Zero:adapterRef.NativePointer), unchecked ((int)driverType), (void *)software, unchecked ((int)flags), featureLevelsRef_, featureLevels, sDKVersion, &deviceOut_, featureLevelRef_, &immediateContextOut_); ((SharpDX.Direct3D11.Device)deviceOut).NativePointer = deviceOut_; immediateContextOut = (immediateContextOut_ == IntPtr.Zero)?null:new SharpDX.Direct3D11.DeviceContext(immediateContextOut_); return(__result__); } }
public static void Fill(Renderer renderer, SharpDX.DXGI.Adapter adapter) { RendererInfo ri = new RendererInfo(); ri.AdapterDesc = adapter.Description.Description; ri.SystemMemory = (UInt64)((IntPtr)adapter.Description.DedicatedSystemMemory).ToPointer(); ri.VideoMemory = (UInt64)((IntPtr)adapter.Description.DedicatedVideoMemory).ToPointer(); ri.SharedMemory = (UInt64)((IntPtr)adapter.Description.SharedSystemMemory).ToPointer(); ri.Outputs = adapter.Outputs.Length; SharpDX.DXGI.Output output = adapter.Outputs[0]; var bounds = output.Description.DesktopBounds; ri.OutputName = output.Description.DeviceName; ri.ScreenBounds = new System.Drawing.Rectangle(new System.Drawing.Point(bounds.Top, bounds.Left), new System.Drawing.Size(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top)); ri.ScreenWidth = output.Description.DesktopBounds.Right - output.Description.DesktopBounds.Left; ri.ScreenHeight = output.Description.DesktopBounds.Bottom - output.Description.DesktopBounds.Top; renderer.Info = ri; }
/// <summary> /// <p>Creates a device that represents the display adapter.</p> /// </summary> /// <param name = "adapterRef"><dd> <p> A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <strong>Note</strong>?? Do not mix the use of DXGI 1.0 (<strong><see cref = "SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref = "SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref = "SharpDX.DXGI.Factory"/></strong> or <strong><see cref = "SharpDX.DXGI.Factory1"/></strong>, but not both in an application. ? </dd></param> /// <param name = "driverType"><dd> <p> The <strong><see cref = "SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create. </p> </dd></param> /// <param name = "software"><dd> <p> A handle to a DLL that implements a software rasterizer. If <em>DriverType</em> is <em>D3D_DRIVER_TYPE_SOFTWARE</em>, <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle. </p> </dd></param> /// <param name = "flags"><dd> <p> The runtime layers to enable (see <strong><see cref = "SharpDX.Direct3D11.DeviceCreationFlags"/></strong>); values can be bitwise OR'd together. </p> </dd></param> /// <param name = "featureLevelsRef"><dd> <p> A reference to an array of <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong>s, which determine the order of feature levels to attempt to create. If <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function uses the following array of feature levels: </p> <pre>{ D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1,};</pre> <strong>Note</strong>?? If the Direct3D 11.1 runtime is present on the computer and <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function won't create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device. To create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device, you must explicitly provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that includes <strong>D3D_FEATURE_LEVEL_11_1</strong>. If you provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that contains <strong>D3D_FEATURE_LEVEL_11_1</strong> on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG. ? </dd></param> /// <param name = "featureLevels"><dd> <p> The number of elements in <em>pFeatureLevels</em>. </p> </dd></param> /// <param name = "sDKVersion"><dd> <p> The SDK version; use <em><see cref = "SdkVersion"/></em>. </p> </dd></param> /// <param name = "deviceOut"><dd> <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object that represents the device created. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.Device"/> will be returned. </p> </dd></param> /// <param name = "featureLevelRef"><dd> <p> If successful, returns the first <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> from the <em>pFeatureLevels</em> array which succeeded. Supply <strong><c>null</c></strong> as an input if you don't need to determine which feature level is supported. </p> </dd></param> /// <param name = "immediateContextOut"><dd> <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.DeviceContext"/></strong> object that represents the device context. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.DeviceContext"/> will be returned. </p> </dd></param> /// <returns><p> This method can return one of the Direct3D 11 Return Codes. </p><p> This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value. </p><p> This method returns <strong><see cref = "SdkComponentMissing"/></strong> if you specify <strong>D3D11_CREATE_DEVICE_DEBUG</strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns> /// <remarks> /// <p> This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644). </p><p> To create a Direct3D 11.1 device (<strong><see cref = "SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device1"/></strong> interface. </p><p> To create a Direct3D 11.2 device (<strong><see cref = "SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device2"/></strong> interface. </p><p> Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking at <em>pFeatureLevel</em> without creating a device. </p><p> For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use <strong>D3D11CreateDeviceAndSwapChain</strong>. </p><p> If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value, <strong>D3D11CreateDevice</strong> returns an <strong><see cref = "SharpDX.Result"/></strong> of E_INVALIDARG. </p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p> In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could mismatch what the adapter was. </p> <p> In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains the other inputs to be: </p> <ul> <li><em>DriverType</em> must be D3D_DRIVER_TYPE_UNKNOWN </li> <li><em>Software</em> must be <strong><c>null</c></strong>. </li> </ul> <p> On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to D3D_DRIVER_TYPE_UNKNOWN; it can be set to either: </p> <ul> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_SOFTWARE, <em>Software</em> cannot be <strong><c>null</c></strong>. </li> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_HARDWARE, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p> The function signature PFN_D3D11_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p><p><strong>Windows?Phone?8: </strong> This API is supported. </p><p><strong>Windows Phone 8.1: </strong> This API is supported. </p> /// </remarks> /// <doc-id>ff476082</doc-id> /// <unmanaged>HRESULT D3D11CreateDevice([In, Optional] IDXGIAdapter* pAdapter,[In] D3D_DRIVER_TYPE DriverType,[In] HINSTANCE Software,[In] unsigned int Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[Out, Fast] ID3D11Device** ppDevice,[Out, Optional] D3D_FEATURE_LEVEL* pFeatureLevel,[Out, Optional] ID3D11DeviceContext** ppImmediateContext)</unmanaged> /// <unmanaged-short>D3D11CreateDevice</unmanaged-short> public static unsafe SharpDX.Result CreateDevice(SharpDX.DXGI.Adapter adapterRef, SharpDX.Direct3D.DriverType driverType, System.IntPtr software, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, System.Int32 featureLevels, System.Int32 sDKVersion, SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D.FeatureLevel featureLevelRef, out SharpDX.Direct3D11.DeviceContext immediateContextOut) { System.IntPtr adapterRef_ = System.IntPtr.Zero; System.IntPtr deviceOut_ = System.IntPtr.Zero; System.IntPtr immediateContextOut_ = System.IntPtr.Zero; SharpDX.Result __result__; adapterRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.DXGI.Adapter>(adapterRef); fixed(void *featureLevelRef_ = &featureLevelRef) fixed(void *featureLevelsRef_ = featureLevelsRef) __result__ = D3D11CreateDevice_((void *)adapterRef_, unchecked ((System.Int32)driverType), (void *)software, unchecked ((System.Int32)flags), featureLevelsRef_, featureLevels, sDKVersion, &deviceOut_, featureLevelRef_, &immediateContextOut_); (deviceOut).NativePointer = deviceOut_; if (immediateContextOut_ != System.IntPtr.Zero) { immediateContextOut = new SharpDX.Direct3D11.DeviceContext(immediateContextOut_); } else { immediateContextOut = null; } return(__result__); }
private void LoadPipeline() { viewport.Width = this.width; viewport.Height = this.height; viewport.MaxDepth = 1.0f; scissorRect.Right = this.width; scissorRect.Bottom = this.height; #if DEBUG // Enable the D3D12 debug layer. { DebugInterface.Get().EnableDebugLayer(); } #endif var fact = new SharpDX.DXGI.Factory1(); SharpDX.DXGI.Adapter adapter = fact.GetAdapter(1); // create device using (var defaultDevice = new Device(adapter, SharpDX.Direct3D.FeatureLevel.Level_12_1)) device = defaultDevice.QueryInterface <SharpDX.Direct3D12.Device2>(); using (var factory = new SharpDX.DXGI.Factory4()) { // Describe and create the command queue. var queueDesc = new CommandQueueDescription(CommandListType.Direct); commandQueue = device.CreateCommandQueue(queueDesc); // Describe and create the swap chain. var swapChainDesc = new SharpDX.DXGI.SwapChainDescription1() { BufferCount = FrameCount, Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, Height = height, Width = width, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Scaling = SharpDX.DXGI.Scaling.Stretch, Stereo = false, SwapEffect = SharpDX.DXGI.SwapEffect.FlipDiscard, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, }; var tempSwapChain = new SharpDX.DXGI.SwapChain1(factory, commandQueue, ref swapChainDesc); swapChain = tempSwapChain.QueryInterface <SharpDX.DXGI.SwapChain3>(); tempSwapChain.Dispose(); frameIndex = swapChain.CurrentBackBufferIndex; using (SharpDX.DXGI.ISwapChainPanelNative nativeObject = ComObject.As <SharpDX.DXGI.ISwapChainPanelNative>(swapChainPanel)) nativeObject.SwapChain = swapChain; } // Create descriptor heaps. // Describe and create a render target view (RTV) descriptor heap. var rtvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.RenderTargetView }; renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); // Create frame resources. var rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart; for (int n = 0; n < FrameCount; n++) { renderTargets[n] = swapChain.GetBackBuffer <Resource>(n); device.CreateRenderTargetView(renderTargets[n], null, rtvHandle); rtvHandle += rtvDescriptorSize; } commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); }
private GpuAdapter(string description, SharpDX.DXGI.Adapter adapter) { Description = description; mAdapter = adapter; }