MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Blast / FindAdapter

Function FindAdapter

samples/SampleBase/core/DeviceManager.cpp:47–97  ·  view source on GitHub ↗

Find an adapter whose name contains the given string.

Source from the content-addressed store, hash-verified

45
46 // Find an adapter whose name contains the given string.
47 IDXGIAdapter* FindAdapter(const WCHAR* targetName, bool& isNv)
48 {
49 IDXGIAdapter* targetAdapter = NULL;
50 IDXGIFactory* IDXGIFactory_0001 = NULL;
51 HRESULT hres = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&IDXGIFactory_0001);
52 if (hres != S_OK)
53 {
54 printf("ERROR in CreateDXGIFactory, %s@%d.\nFor more info, get log from debug D3D runtime: (1) Install DX SDK, and enable Debug D3D from DX Control Panel Utility. (2) Install and start DbgView. (3) Try running the program again.\n",__FILE__,__LINE__);
55 return targetAdapter;
56 }
57
58 unsigned int adapterNo = 0;
59 while (SUCCEEDED(hres))
60 {
61 IDXGIAdapter* pAdapter = NULL;
62 hres = IDXGIFactory_0001->EnumAdapters(adapterNo, (IDXGIAdapter**)&pAdapter);
63
64 if (SUCCEEDED(hres))
65 {
66 DXGI_ADAPTER_DESC aDesc;
67 pAdapter->GetDesc(&aDesc);
68
69 // If no name is specified, return the first adapater. This is the same behaviour as the
70 // default specified for D3D11CreateDevice when no adapter is specified.
71 if (wcslen(targetName) == 0)
72 {
73 targetAdapter = pAdapter;
74 isNv = IsNvDeviceID(aDesc.VendorId);
75 break;
76 }
77
78 std::wstring aName = aDesc.Description;
79 if (aName.find(targetName) != std::string::npos)
80 {
81 targetAdapter = pAdapter;
82 isNv = IsNvDeviceID(aDesc.VendorId);
83 }
84 else
85 {
86 pAdapter->Release();
87 }
88 }
89
90 adapterNo++;
91 }
92
93 if (IDXGIFactory_0001)
94 IDXGIFactory_0001->Release();
95
96 return targetAdapter;
97 }
98
99 // Adjust window rect so that it is centred on the given adapter. Clamps to fit if it's too big.
100 RECT MoveWindowOntoAdapter(IDXGIAdapter* targetAdapter, const RECT& rect)

Callers 1

Calls 3

IsNvDeviceIDFunction · 0.85
findMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected