From 5ef4167c559a4df98d2346135567f6b92bb46188 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sun, 21 Nov 2010 15:34:04 +0000 Subject: [PATCH] DX11: Dynamically load dxgi.dll and d3d11.dll. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6451 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_VideoDX11/Plugin_VideoDX11.vcproj | 12 +-- .../Plugins/Plugin_VideoDX11/Src/D3DBase.cpp | 84 +++++++++++++++---- Source/Plugins/Plugin_VideoDX11/Src/D3DBase.h | 6 ++ Source/Plugins/Plugin_VideoDX11/Src/main.cpp | 7 +- 4 files changed, 86 insertions(+), 23 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj index 6acf8fc07c..cf2a4d49e4 100644 --- a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj +++ b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj @@ -91,7 +91,7 @@ EnumAdapters(g_ActiveConfig.iAdapter, &adapter); @@ -145,7 +192,7 @@ HRESULT Create(HWND wnd) #else D3D11_CREATE_DEVICE_FLAG device_flags = D3D11_CREATE_DEVICE_SINGLETHREADED; #endif - hr = D3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, device_flags, + hr = PD3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, device_flags, supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS, D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device, &featlevel, &context); @@ -192,12 +239,6 @@ HRESULT Create(HWND wnd) void Close() { - // unload D3DX11 - FreeLibrary(hD3DXDll); - PD3DX11FilterTexture = NULL; - PD3DX11SaveTextureToFileA = NULL; - PD3DX11SaveTextureToFileW = NULL; - // release all bound resources context->ClearState(); SAFE_RELEASE(backbuf); @@ -217,6 +258,17 @@ void Close() NOTICE_LOG(VIDEO, "Successfully released all device references!"); } device = NULL; + + // unload DLLs + if(hD3DXDll) FreeLibrary(hD3DXDll); + PD3DX11FilterTexture = NULL; + PD3DX11SaveTextureToFileA = NULL; + PD3DX11SaveTextureToFileW = NULL; + + if(hD3DXDll) FreeLibrary(hD3DXDll); + PD3D11CreateDeviceAndSwapChain = NULL; + + UnloadDXGI(); } /* just returning the 4_0 ones here */ diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DBase.h b/Source/Plugins/Plugin_VideoDX11/Src/D3DBase.h index c1a70c803f..94e5fa4648 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/D3DBase.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DBase.h @@ -31,6 +31,9 @@ class D3DTexture2D; namespace D3D { +HRESULT GetDXGIFuncPointers(); +void UnloadDXGI(); + HRESULT Create(HWND wnd); void Close(); @@ -86,3 +89,6 @@ extern D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW; #else #define PD3DX11SaveTextureToFile PD3DX11SaveTextureToFileA #endif + +typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**); +extern CREATEDXGIFACTORY PCreateDXGIFactory; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index 5066a79ac3..e6b64d885d 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -152,9 +152,12 @@ void DllConfig(void *_hParent) { g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str()); + HRESULT hr = D3D::GetDXGIFuncPointers(); + if (FAILED(hr)) return; + IDXGIFactory* factory; IDXGIAdapter* ad; - const HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); + hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); if (FAILED(hr)) PanicAlert("Failed to create IDXGIFactory object"); @@ -185,6 +188,8 @@ void DllConfig(void *_hParent) g_Config.Save((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str()); factory->Release(); + + D3D::UnloadDXGI(); } void Initialize(void *init)