mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-30 15:32:47 +00:00
DX11: Dynamically load dxgi.dll and d3d11.dll.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6451 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
ee21237d6a
commit
5ef4167c55
@ -91,7 +91,7 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalOptions=""..\..\core\common\win32\release\common.lib""
|
AdditionalOptions=""..\..\core\common\win32\release\common.lib""
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib dxguid.lib d3d11.lib dxgi.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib dxguid.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||||
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX11.dll"
|
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX11.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
@ -199,7 +199,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib dxguid.lib d3d11.lib dxgi.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib dxguid.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11.dll"
|
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
@ -297,7 +297,7 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalOptions=""..\..\core\common\win32\debug\common.lib""
|
AdditionalOptions=""..\..\core\common\win32\debug\common.lib""
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib d3d11.lib dxgi.lib Rpcrt4.lib winmm.lib vfw32.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib Rpcrt4.lib winmm.lib vfw32.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
||||||
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_VideoDX11D.dll"
|
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_VideoDX11D.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
@ -393,7 +393,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib d3d11.lib dxgi.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
||||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11D.dll"
|
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11D.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
@ -499,7 +499,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib d3d11.lib dxgi.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
||||||
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX11DF.dll"
|
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX11DF.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
@ -608,7 +608,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib d3d11.lib dxgi.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib uuid.lib dxguid.lib Rpcrt4.lib winmm.lib vfw32.lib"
|
||||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11DF.dll"
|
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX11DF.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
|
@ -30,6 +30,13 @@ D3DX11FILTERTEXTURETYPE PD3DX11FilterTexture = NULL;
|
|||||||
D3DX11SAVETEXTURETOFILEATYPE PD3DX11SaveTextureToFileA = NULL;
|
D3DX11SAVETEXTURETOFILEATYPE PD3DX11SaveTextureToFileA = NULL;
|
||||||
D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW = NULL;
|
D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW = NULL;
|
||||||
|
|
||||||
|
CREATEDXGIFACTORY PCreateDXGIFactory = NULL;
|
||||||
|
HINSTANCE hDXGIDll = NULL;
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI* D3D11CREATEDEVICEANDSWAPCHAIN)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT, CONST DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D11Device**, D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
|
||||||
|
D3D11CREATEDEVICEANDSWAPCHAIN PD3D11CreateDeviceAndSwapChain = NULL;
|
||||||
|
HINSTANCE hD3DDll = NULL;
|
||||||
|
|
||||||
namespace D3D
|
namespace D3D
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -53,16 +60,28 @@ unsigned int xres, yres;
|
|||||||
|
|
||||||
bool bFrameInProgress = false;
|
bool bFrameInProgress = false;
|
||||||
|
|
||||||
HRESULT Create(HWND wnd)
|
HRESULT GetDXGIFuncPointers()
|
||||||
{
|
{
|
||||||
hWnd = wnd;
|
hDXGIDll = LoadLibraryA("dxgi.dll");
|
||||||
HRESULT hr;
|
if (!hDXGIDll)
|
||||||
|
{
|
||||||
|
MessageBoxA(NULL, "Failed to load dxgi.dll", "Critical error", MB_OK | MB_ICONERROR);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
PCreateDXGIFactory = (CREATEDXGIFACTORY)GetProcAddress(hDXGIDll, "CreateDXGIFactory");
|
||||||
|
if (PCreateDXGIFactory == NULL) MessageBoxA(NULL, "GetProcAddress failed for CreateDXGIFactory!", "Critical error", MB_OK | MB_ICONERROR);
|
||||||
|
|
||||||
RECT client;
|
return S_OK;
|
||||||
GetClientRect(hWnd, &client);
|
}
|
||||||
xres = client.right - client.left;
|
|
||||||
yres = client.bottom - client.top;
|
|
||||||
|
|
||||||
|
void UnloadDXGI()
|
||||||
|
{
|
||||||
|
if(hDXGIDll) FreeLibrary(hDXGIDll);
|
||||||
|
PCreateDXGIFactory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT GetD3DFuncPointers()
|
||||||
|
{
|
||||||
// try to load D3DX11 first to check whether we have proper runtime support
|
// try to load D3DX11 first to check whether we have proper runtime support
|
||||||
// try to use the dll the plugin was compiled against first - don't bother about debug runtimes
|
// try to use the dll the plugin was compiled against first - don't bother about debug runtimes
|
||||||
hD3DXDll = LoadLibraryA(StringFromFormat("d3dx11_%d.dll", D3DX11_SDK_VERSION).c_str());
|
hD3DXDll = LoadLibraryA(StringFromFormat("d3dx11_%d.dll", D3DX11_SDK_VERSION).c_str());
|
||||||
@ -93,11 +112,39 @@ HRESULT Create(HWND wnd)
|
|||||||
PD3DX11SaveTextureToFileW = (D3DX11SAVETEXTURETOFILEWTYPE)GetProcAddress(hD3DXDll, "D3DX11SaveTextureToFileW");
|
PD3DX11SaveTextureToFileW = (D3DX11SAVETEXTURETOFILEWTYPE)GetProcAddress(hD3DXDll, "D3DX11SaveTextureToFileW");
|
||||||
if (PD3DX11SaveTextureToFileW == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11SaveTextureToFileW!", "Critical error", MB_OK | MB_ICONERROR);
|
if (PD3DX11SaveTextureToFileW == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11SaveTextureToFileW!", "Critical error", MB_OK | MB_ICONERROR);
|
||||||
|
|
||||||
// D3DX11 is fine, initialize D3D11
|
// D3DX11 is fine, check DXGI and D3D11
|
||||||
|
HRESULT hr = GetDXGIFuncPointers();
|
||||||
|
if (FAILED(hr)) return hr;
|
||||||
|
|
||||||
|
hD3DDll = LoadLibraryA("d3d11.dll");
|
||||||
|
if (!hD3DDll)
|
||||||
|
{
|
||||||
|
MessageBoxA(NULL, "Failed to load d3d11.dll", "Critical error", MB_OK | MB_ICONERROR);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
PD3D11CreateDeviceAndSwapChain = (D3D11CREATEDEVICEANDSWAPCHAIN)GetProcAddress(hD3DDll, "D3D11CreateDeviceAndSwapChain");
|
||||||
|
if (PD3D11CreateDeviceAndSwapChain == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3D11CreateDeviceAndSwapChain!", "Critical error", MB_OK | MB_ICONERROR);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT Create(HWND wnd)
|
||||||
|
{
|
||||||
|
hWnd = wnd;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
RECT client;
|
||||||
|
GetClientRect(hWnd, &client);
|
||||||
|
xres = client.right - client.left;
|
||||||
|
yres = client.bottom - client.top;
|
||||||
|
|
||||||
|
hr = GetD3DFuncPointers();
|
||||||
|
if (FAILED(hr)) return hr;
|
||||||
|
|
||||||
IDXGIFactory* factory;
|
IDXGIFactory* factory;
|
||||||
IDXGIAdapter* adapter;
|
IDXGIAdapter* adapter;
|
||||||
IDXGIOutput* output;
|
IDXGIOutput* output;
|
||||||
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
||||||
if (FAILED(hr)) MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
|
if (FAILED(hr)) MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
|
||||||
|
|
||||||
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
|
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
|
||||||
@ -145,7 +192,7 @@ HRESULT Create(HWND wnd)
|
|||||||
#else
|
#else
|
||||||
D3D11_CREATE_DEVICE_FLAG device_flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
|
D3D11_CREATE_DEVICE_FLAG device_flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
|
||||||
#endif
|
#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,
|
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
|
||||||
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
|
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
|
||||||
&featlevel, &context);
|
&featlevel, &context);
|
||||||
@ -192,12 +239,6 @@ HRESULT Create(HWND wnd)
|
|||||||
|
|
||||||
void Close()
|
void Close()
|
||||||
{
|
{
|
||||||
// unload D3DX11
|
|
||||||
FreeLibrary(hD3DXDll);
|
|
||||||
PD3DX11FilterTexture = NULL;
|
|
||||||
PD3DX11SaveTextureToFileA = NULL;
|
|
||||||
PD3DX11SaveTextureToFileW = NULL;
|
|
||||||
|
|
||||||
// release all bound resources
|
// release all bound resources
|
||||||
context->ClearState();
|
context->ClearState();
|
||||||
SAFE_RELEASE(backbuf);
|
SAFE_RELEASE(backbuf);
|
||||||
@ -217,6 +258,17 @@ void Close()
|
|||||||
NOTICE_LOG(VIDEO, "Successfully released all device references!");
|
NOTICE_LOG(VIDEO, "Successfully released all device references!");
|
||||||
}
|
}
|
||||||
device = NULL;
|
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 */
|
/* just returning the 4_0 ones here */
|
||||||
|
@ -31,6 +31,9 @@ class D3DTexture2D;
|
|||||||
namespace D3D
|
namespace D3D
|
||||||
{
|
{
|
||||||
|
|
||||||
|
HRESULT GetDXGIFuncPointers();
|
||||||
|
void UnloadDXGI();
|
||||||
|
|
||||||
HRESULT Create(HWND wnd);
|
HRESULT Create(HWND wnd);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
@ -86,3 +89,6 @@ extern D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW;
|
|||||||
#else
|
#else
|
||||||
#define PD3DX11SaveTextureToFile PD3DX11SaveTextureToFileA
|
#define PD3DX11SaveTextureToFile PD3DX11SaveTextureToFileA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**);
|
||||||
|
extern CREATEDXGIFACTORY PCreateDXGIFactory;
|
||||||
|
@ -152,9 +152,12 @@ void DllConfig(void *_hParent)
|
|||||||
{
|
{
|
||||||
g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
|
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;
|
IDXGIFactory* factory;
|
||||||
IDXGIAdapter* ad;
|
IDXGIAdapter* ad;
|
||||||
const HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
PanicAlert("Failed to create IDXGIFactory object");
|
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());
|
g_Config.Save((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
|
||||||
|
|
||||||
factory->Release();
|
factory->Release();
|
||||||
|
|
||||||
|
D3D::UnloadDXGI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize(void *init)
|
void Initialize(void *init)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user