@@ -210,31 +210,41 @@ HRESULT EvaluateModel(
210210
211211 if (deviceCreationLocation == DeviceCreationLocation::ClientCode && deviceType != DeviceType::CPU)
212212 {
213- // Creating the device on the client and using it to create the video frame and initialize the session makes sure that everything is on
214- // the same device. This usually avoids an expensive cross-device and cross-videoframe copy via the VideoFrame pipeline.
215- com_ptr<ID3D11Device> d3d11Device ;
216- HRESULT hr = D3D11CreateDevice ( nullptr , D3D_DRIVER_TYPE_HARDWARE, nullptr , D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr , 0 , D3D11_SDK_VERSION, d3d11Device. put (), nullptr , nullptr );
213+ // Enumerate Adapters to pick the requested one.
214+ com_ptr<IDXGIFactory6> factory;
215+ HRESULT hr = CreateDXGIFactory ( __uuidof (IDXGIFactory6), factory. put_void ()) ;
216+ THROW_IF_FAILED (hr );
217217
218- if (FAILED (hr))
218+ com_ptr<IDXGIAdapter> adapter;
219+ switch (deviceType)
219220 {
220- throw hresult (hr);
221+ case DeviceType::DefaultGPU:
222+ hr = factory->EnumAdapterByGpuPreference (0 , DXGI_GPU_PREFERENCE_UNSPECIFIED, __uuidof (IDXGIAdapter), adapter.put_void ());
223+ break ;
224+ case DeviceType::MinPowerGPU:
225+ hr = factory->EnumAdapterByGpuPreference (0 , DXGI_GPU_PREFERENCE_MINIMUM_POWER, __uuidof (IDXGIAdapter), adapter.put_void ());
226+ break ;
227+ case DeviceType::HighPerfGPU:
228+ hr = factory->EnumAdapterByGpuPreference (0 , DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, __uuidof (IDXGIAdapter), adapter.put_void ());
229+ break ;
230+ default :
231+ throw hresult (E_INVALIDARG);
221232 }
233+ THROW_IF_FAILED (hr);
222234
223- com_ptr<IDXGIDevice> dxgiDevice;
224- hr = d3d11Device->QueryInterface (IID_PPV_ARGS (dxgiDevice.put ()));
235+ // Creating the device on the client and using it to create the video frame and initialize the session makes sure that everything is on
236+ // the same device. This usually avoids an expensive cross-device and cross-videoframe copy via the VideoFrame pipeline.
237+ com_ptr<ID3D11Device> d3d11Device;
238+ hr = D3D11CreateDevice (adapter.get (), D3D_DRIVER_TYPE_UNKNOWN, nullptr , D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr , 0 , D3D11_SDK_VERSION, d3d11Device.put (), nullptr , nullptr );
239+ THROW_IF_FAILED (hr);
225240
226- if (FAILED (hr))
227- {
228- throw hresult (hr);
229- }
241+ com_ptr<IDXGIDevice> dxgiDevice;
242+ hr = d3d11Device->QueryInterface (__uuidof (IDXGIDevice), dxgiDevice.put_void ());
243+ THROW_IF_FAILED (hr);
230244
231245 com_ptr<IInspectable> inspectableDevice;
232246 hr = CreateDirect3D11DeviceFromDXGIDevice (dxgiDevice.get (), inspectableDevice.put ());
233-
234- if (FAILED (hr))
235- {
236- throw hresult (hr);
237- }
247+ THROW_IF_FAILED (hr);
238248
239249 winrtDevice = inspectableDevice.as <IDirect3DDevice>();
240250 LearningModelDevice learningModelDevice = LearningModelDevice::CreateFromDirect3D11Device (winrtDevice);
0 commit comments