@@ -35,7 +35,7 @@ use winapi::{
3535 shared:: {
3636 dxgi:: { IDXGIAdapter , IDXGIFactory , IDXGISwapChain } ,
3737 dxgiformat,
38- minwindef:: { FALSE , UINT } ,
38+ minwindef:: { FALSE , UINT , HMODULE } ,
3939 windef:: { HWND , RECT } ,
4040 winerror,
4141 } ,
@@ -105,6 +105,7 @@ impl fmt::Debug for ViewInfo {
105105pub struct Instance {
106106 pub ( crate ) factory : ComPtr < IDXGIFactory > ,
107107 pub ( crate ) dxgi_version : dxgi:: DxgiVersion ,
108+ library : libloading:: Library ,
108109}
109110
110111unsafe impl Send for Instance { }
@@ -245,9 +246,12 @@ impl hal::Instance<Backend> for Instance {
245246 match dxgi:: get_dxgi_factory ( ) {
246247 Ok ( ( factory, dxgi_version) ) => {
247248 info ! ( "DXGI version: {:?}" , dxgi_version) ;
249+ let library = libloading:: Library :: new ( "d3d11.dll" )
250+ . map_err ( |_| hal:: UnsupportedBackend ) ?;
248251 Ok ( Instance {
249252 factory,
250253 dxgi_version,
254+ library,
251255 } )
252256 }
253257 Err ( hr) => {
@@ -258,9 +262,32 @@ impl hal::Instance<Backend> for Instance {
258262 }
259263
260264 fn enumerate_adapters ( & self ) -> Vec < adapter:: Adapter < Backend > > {
265+ type Fun = extern "system" fn (
266+ * mut IDXGIAdapter ,
267+ UINT ,
268+ HMODULE ,
269+ UINT ,
270+ * const UINT ,
271+ UINT ,
272+ UINT ,
273+ * mut * mut d3d11:: ID3D11Device ,
274+ * mut UINT ,
275+ * mut * mut d3d11:: ID3D11DeviceContext ,
276+ ) -> winerror:: HRESULT ;
277+
261278 let mut adapters = Vec :: new ( ) ;
262279 let mut idx = 0 ;
263280
281+ let func: libloading:: Symbol < Fun > = match unsafe {
282+ self . library . get ( b"D3D11CreateDevice" )
283+ } {
284+ Ok ( func) => func,
285+ Err ( e) => {
286+ error ! ( "Unable to get device creation function: {:?}" , e) ;
287+ return Vec :: new ( ) ;
288+ }
289+ } ;
290+
264291 while let Ok ( ( adapter, info) ) =
265292 dxgi:: get_adapter ( idx, self . factory . as_raw ( ) , self . dxgi_version )
266293 {
@@ -273,20 +300,18 @@ impl hal::Instance<Backend> for Instance {
273300 let feature_level = get_feature_level ( adapter. as_raw ( ) ) ;
274301
275302 let mut device = ptr:: null_mut ( ) ;
276- let hr = unsafe {
277- d3d11:: D3D11CreateDevice (
278- adapter. as_raw ( ) as * mut _ ,
279- d3dcommon:: D3D_DRIVER_TYPE_UNKNOWN ,
280- ptr:: null_mut ( ) ,
281- 0 ,
282- [ feature_level] . as_ptr ( ) ,
283- 1 ,
284- d3d11:: D3D11_SDK_VERSION ,
285- & mut device as * mut * mut _ as * mut * mut _ ,
286- ptr:: null_mut ( ) ,
287- ptr:: null_mut ( ) ,
288- )
289- } ;
303+ let hr = func (
304+ adapter. as_raw ( ) as * mut _ ,
305+ d3dcommon:: D3D_DRIVER_TYPE_UNKNOWN ,
306+ ptr:: null_mut ( ) ,
307+ 0 ,
308+ [ feature_level] . as_ptr ( ) ,
309+ 1 ,
310+ d3d11:: D3D11_SDK_VERSION ,
311+ & mut device as * mut * mut _ as * mut * mut _ ,
312+ ptr:: null_mut ( ) ,
313+ ptr:: null_mut ( ) ,
314+ ) ;
290315
291316 if !winerror:: SUCCEEDED ( hr) {
292317 continue ;
@@ -536,7 +561,7 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
536561 // TODO: deferred context => 1 cxt/queue?
537562 let queue_groups = families
538563 . into_iter ( )
539- . map ( |& ( family , prio) | {
564+ . map ( |& ( _family , prio) | {
540565 assert_eq ! ( prio. len( ) , 1 ) ;
541566 let mut group = queue:: QueueGroup :: new ( queue:: QueueFamilyId ( 0 ) ) ;
542567
@@ -700,7 +725,7 @@ impl window::Surface<Backend> for Surface {
700725 true
701726 }
702727
703- fn capabilities ( & self , physical_device : & PhysicalDevice ) -> window:: SurfaceCapabilities {
728+ fn capabilities ( & self , _physical_device : & PhysicalDevice ) -> window:: SurfaceCapabilities {
704729 let current_extent = unsafe {
705730 let mut rect: RECT = mem:: zeroed ( ) ;
706731 assert_ne ! (
0 commit comments