D3D11CreateDeviceAndSwapChain function (d3d11.h)

Creates a device that represents the display adapter and a swap chain used for rendering.

Syntax

HRESULT D3D11CreateDeviceAndSwapChain(
  [in, optional]  IDXGIAdapter               *pAdapter,
                  D3D_DRIVER_TYPE            DriverType,
                  HMODULE                    Software,
                  UINT                       Flags,
  [in, optional]  const D3D_FEATURE_LEVEL    *pFeatureLevels,
                  UINT                       FeatureLevels,
                  UINT                       SDKVersion,
  [in, optional]  const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
  [out, optional] IDXGISwapChain             **ppSwapChain,
  [out, optional] ID3D11Device               **ppDevice,
  [out, optional] D3D_FEATURE_LEVEL          *pFeatureLevel,
  [out, optional] ID3D11DeviceContext        **ppImmediateContext
);

Parameters

[in, optional] pAdapter

Type: IDXGIAdapter*

A pointer to the video adapter to use when creating a device. Pass NULL to use the default adapter, which is the first adapter enumerated by IDXGIFactory1::EnumAdapters.

Note  Do not mix the use of DXGI 1.0 (IDXGIFactory) and DXGI 1.1 (IDXGIFactory1) in an application. Use IDXGIFactory or IDXGIFactory1, but not both in an application.
 

DriverType

Type: D3D_DRIVER_TYPE

The D3D_DRIVER_TYPE, which represents the driver type to create.

Software

Type: HMODULE

A handle to a DLL that implements a software rasterizer. If DriverType is D3D_DRIVER_TYPE_SOFTWARE, Software must not be NULL. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle. The value should be non-NULL when D3D_DRIVER_TYPE is D3D_DRIVER_TYPE_SOFTWARE and NULL otherwise.

Flags

Type: UINT

The runtime layers to enable (see D3D11_CREATE_DEVICE_FLAG); values can be bitwise OR'd together.

[in, optional] pFeatureLevels

Type: const D3D_FEATURE_LEVEL*

A pointer to an array of D3D_FEATURE_LEVELs, which determine the order of feature levels to attempt to create. If pFeatureLevels is set to NULL, this function uses the following array of feature levels:


{
    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,
};
          
Note  If the Direct3D 11.1 runtime is present on the computer and pFeatureLevels is set to NULL, this function won't create a D3D_FEATURE_LEVEL_11_1 device. To create a D3D_FEATURE_LEVEL_11_1 device, you must explicitly provide a D3D_FEATURE_LEVEL array that includes D3D_FEATURE_LEVEL_11_1. If you provide a D3D_FEATURE_LEVEL array that contains D3D_FEATURE_LEVEL_11_1 on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.
 

FeatureLevels

Type: UINT

The number of elements in pFeatureLevels.

SDKVersion

Type: UINT

The SDK version; use D3D11_SDK_VERSION.

[in, optional] pSwapChainDesc

Type: const DXGI_SWAP_CHAIN_DESC*

A pointer to a swap chain description (see DXGI_SWAP_CHAIN_DESC) that contains initialization parameters for the swap chain.

[out, optional] ppSwapChain

Type: IDXGISwapChain**

Returns the address of a pointer to the IDXGISwapChain object that represents the swap chain used for rendering.

[out, optional] ppDevice

Type: ID3D11Device**

Returns the address of a pointer to an ID3D11Device object that represents the device created. If this parameter is NULL, no ID3D11Device will be returned'.

[out, optional] pFeatureLevel

Type: D3D_FEATURE_LEVEL*

Returns a pointer to a D3D_FEATURE_LEVEL, which represents the first element in an array of feature levels supported by the device. Supply NULL as an input if you don't need to determine which feature level is supported.

[out, optional] ppImmediateContext

Type: ID3D11DeviceContext**

Returns the address of a pointer to an ID3D11DeviceContext object that represents the device context. If this parameter is NULL, no ID3D11DeviceContext will be returned.

Return value

Type: HRESULT

This method can return one of the Direct3D 11 Return Codes.

This method returns DXGI_ERROR_NOT_CURRENTLY_AVAILABLE if you call it in a Session 0 process.

This method returns E_INVALIDARG if you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value.

This method returns DXGI_ERROR_SDK_COMPONENT_MISSING if you specify D3D11_CREATE_DEVICE_DEBUG in Flags and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version.

Remarks

Note  If you call this method in a Session 0 process, it returns DXGI_ERROR_NOT_CURRENTLY_AVAILABLE.
 
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).

To create a Direct3D 11.1 device (ID3D11Device1), 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 ID3D11Device with this function, and then call the QueryInterface method on the ID3D11Device object to obtain the ID3D11Device1 interface.

To create a Direct3D 11.2 device (ID3D11Device2), which is available on Windows 8.1 and Windows Server 2012 R2, you first create a ID3D11Device with this function, and then call the QueryInterface method on the ID3D11Device object to obtain the ID3D11Device2 interface.

Also, see the remarks section in D3D11CreateDevice for details about input parameter dependencies. To create a device without creating a swap chain, use the D3D11CreateDevice function.

If you set the pAdapter parameter to a non-NULL value, you must also set the DriverType parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value, D3D11CreateDeviceAndSwapChain returns an HRESULT of E_INVALIDARG.

The function signature PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking.

Usage notes

Note  The D3D11CreateDeviceAndSwapChain function does not exist for Windows Store apps. Instead, Windows Store apps use the D3D11CreateDevice function and then use the IDXGIFactory2::CreateSwapChainForCoreWindow method.
 
Note  This function has not been updated to support recent additional features of swap chain creation. For the most up-to-date swap chain creation methods, refer to the methods of IDXGIFactory2 (including CreateSwapChainForHwnd, CreateSwapChainForCoreWindow and CreateSwapChainForComposition).
 
Windows Phone 8: This API is supported.

Requirements

Requirement Value
Target Platform Windows
Header d3d11.h
Library D3D11.lib
DLL D3D11.dll

See also

Core Functions