@@ -5,6 +5,7 @@ extern crate auxil;
55extern crate range_alloc;
66#[ macro_use]
77extern crate bitflags;
8+ extern crate libloading;
89#[ macro_use]
910extern crate log;
1011extern crate parking_lot;
@@ -39,7 +40,7 @@ use hal::{
3940use range_alloc:: RangeAllocator ;
4041
4142use winapi:: shared:: dxgi:: { IDXGIAdapter , IDXGIFactory , IDXGISwapChain } ;
42- use winapi:: shared:: minwindef:: { FALSE , UINT } ;
43+ use winapi:: shared:: minwindef:: { FALSE , UINT , HMODULE } ;
4344use winapi:: shared:: windef:: { HWND , RECT } ;
4445use winapi:: shared:: { dxgiformat, winerror} ;
4546use winapi:: um:: winuser:: GetClientRect ;
@@ -116,6 +117,7 @@ impl fmt::Debug for ViewInfo {
116117pub struct Instance {
117118 pub ( crate ) factory : ComPtr < IDXGIFactory > ,
118119 pub ( crate ) dxgi_version : dxgi:: DxgiVersion ,
120+ library : libloading:: Library ,
119121}
120122
121123unsafe impl Send for Instance { }
@@ -256,9 +258,12 @@ impl hal::Instance<Backend> for Instance {
256258 match dxgi:: get_dxgi_factory ( ) {
257259 Ok ( ( factory, dxgi_version) ) => {
258260 info ! ( "DXGI version: {:?}" , dxgi_version) ;
261+ let library = libloading:: Library :: new ( "d3d11.dll" )
262+ . map_err ( |_| hal:: UnsupportedBackend ) ?;
259263 Ok ( Instance {
260264 factory,
261265 dxgi_version,
266+ library,
262267 } )
263268 }
264269 Err ( hr) => {
@@ -269,9 +274,32 @@ impl hal::Instance<Backend> for Instance {
269274 }
270275
271276 fn enumerate_adapters ( & self ) -> Vec < adapter:: Adapter < Backend > > {
277+ type Fun = extern "system" fn (
278+ * mut IDXGIAdapter ,
279+ UINT ,
280+ HMODULE ,
281+ UINT ,
282+ * const UINT ,
283+ UINT ,
284+ UINT ,
285+ * mut * mut d3d11:: ID3D11Device ,
286+ * mut UINT ,
287+ * mut * mut d3d11:: ID3D11DeviceContext ,
288+ ) -> winerror:: HRESULT ;
289+
272290 let mut adapters = Vec :: new ( ) ;
273291 let mut idx = 0 ;
274292
293+ let func: libloading:: Symbol < Fun > = match unsafe {
294+ self . library . get ( b"D3D11CreateDevice" )
295+ } {
296+ Ok ( func) => func,
297+ Err ( e) => {
298+ error ! ( "Unable to get device creation function: {:?}" , e) ;
299+ return Vec :: new ( ) ;
300+ }
301+ } ;
302+
275303 while let Ok ( ( adapter, info) ) =
276304 dxgi:: get_adapter ( idx, self . factory . as_raw ( ) , self . dxgi_version )
277305 {
@@ -284,20 +312,18 @@ impl hal::Instance<Backend> for Instance {
284312 let feature_level = get_feature_level ( adapter. as_raw ( ) ) ;
285313
286314 let mut device = ptr:: null_mut ( ) ;
287- let hr = unsafe {
288- d3d11:: D3D11CreateDevice (
289- adapter. as_raw ( ) as * mut _ ,
290- d3dcommon:: D3D_DRIVER_TYPE_UNKNOWN ,
291- ptr:: null_mut ( ) ,
292- 0 ,
293- [ feature_level] . as_ptr ( ) ,
294- 1 ,
295- d3d11:: D3D11_SDK_VERSION ,
296- & mut device as * mut * mut _ as * mut * mut _ ,
297- ptr:: null_mut ( ) ,
298- ptr:: null_mut ( ) ,
299- )
300- } ;
315+ let hr = func (
316+ adapter. as_raw ( ) as * mut _ ,
317+ d3dcommon:: D3D_DRIVER_TYPE_UNKNOWN ,
318+ ptr:: null_mut ( ) ,
319+ 0 ,
320+ [ feature_level] . as_ptr ( ) ,
321+ 1 ,
322+ d3d11:: D3D11_SDK_VERSION ,
323+ & mut device as * mut * mut _ as * mut * mut _ ,
324+ ptr:: null_mut ( ) ,
325+ ptr:: null_mut ( ) ,
326+ ) ;
301327
302328 if !winerror:: SUCCEEDED ( hr) {
303329 continue ;
@@ -547,7 +573,7 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
547573 // TODO: deferred context => 1 cxt/queue?
548574 let queue_groups = families
549575 . into_iter ( )
550- . map ( |& ( family , prio) | {
576+ . map ( |& ( _family , prio) | {
551577 assert_eq ! ( prio. len( ) , 1 ) ;
552578 let mut group = queue:: QueueGroup :: new ( queue:: QueueFamilyId ( 0 ) ) ;
553579
@@ -711,7 +737,7 @@ impl window::Surface<Backend> for Surface {
711737 true
712738 }
713739
714- fn capabilities ( & self , physical_device : & PhysicalDevice ) -> window:: SurfaceCapabilities {
740+ fn capabilities ( & self , _physical_device : & PhysicalDevice ) -> window:: SurfaceCapabilities {
715741 let current_extent = unsafe {
716742 let mut rect: RECT = mem:: zeroed ( ) ;
717743 assert_ne ! (
0 commit comments