1 #include <windows.h>
2 
3 #include <d3d11.h>
4 #pragma comment (lib, "d3d11.lib")
5 
6 HINSTANCE g_hInst = NULL;
7 D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
8 D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
9 ID3D11Device* g_pd3dDevice = NULL;
10 ID3D11DeviceContext* g_pImmediateContext = NULL;
11 IDXGISwapChain* g_pSwapChain = NULL;
12 
InitDevice()13 static HRESULT InitDevice()
14 {
15     HRESULT hr = S_OK;
16 
17     UINT width = 640;
18     UINT height = 480;
19 
20     UINT createDeviceFlags = 0;
21 
22     D3D_DRIVER_TYPE driverTypes[] =
23     {
24         D3D_DRIVER_TYPE_HARDWARE,
25         D3D_DRIVER_TYPE_WARP,
26         D3D_DRIVER_TYPE_REFERENCE,
27     };
28     UINT numDriverTypes = ARRAYSIZE(driverTypes);
29 
30     D3D_FEATURE_LEVEL featureLevels[] =
31     {
32         D3D_FEATURE_LEVEL_11_0,
33         D3D_FEATURE_LEVEL_10_1,
34         D3D_FEATURE_LEVEL_10_0,
35     };
36     UINT numFeatureLevels = ARRAYSIZE(featureLevels);
37 
38     DXGI_SWAP_CHAIN_DESC sd;
39     ZeroMemory( &sd, sizeof( sd ) );
40     sd.BufferCount = 1;
41     sd.BufferDesc.Width = width;
42     sd.BufferDesc.Height = height;
43 #ifdef CHECK_NV12
44     sd.BufferDesc.Format = DXGI_FORMAT_NV12;
45 #else
46     sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
47 #endif
48     sd.BufferDesc.RefreshRate.Numerator = 60;
49     sd.BufferDesc.RefreshRate.Denominator = 1;
50     sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
51     sd.OutputWindow = NULL; //g_hWnd;
52     sd.SampleDesc.Count = 1;
53     sd.SampleDesc.Quality = 0;
54     sd.Windowed = TRUE;
55 
56     for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
57     {
58         g_driverType = driverTypes[driverTypeIndex];
59         hr = D3D11CreateDeviceAndSwapChain(NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
60                 D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);
61         if (SUCCEEDED(hr))
62             break;
63     }
64     if (FAILED(hr))
65         return hr;
66 
67     return S_OK;
68 }
69 
main(int,char **)70 int main(int /*argc*/, char** /*argv*/)
71 {
72     InitDevice();
73     return 0;
74 }
75