D3D: Reintroduce depencency on D3DX11 because it's the most straightforward way to bring back some broken features.

The Dolphin development team is incapable of providing sufficient replacement for its previous usage in Dolphin and the advantages of dropping the dependency do not justify the removal of screenshots and texture dumping.

From now on, d3dx11.h, d3dx11async.h, d3dx11core.h and d3dx11tex.h are required to be stored somewhere in the header include path. I don't know if this is the case for anyone else than me, but I can't really say that I care after having people randomly merge unfinished branches into master.
This commit is contained in:
Tony Wasserka
2013-11-10 00:06:32 +01:00
parent 8923968b47
commit a83c239765
2 changed files with 84 additions and 1 deletions

View File

@ -17,6 +17,13 @@ D3DREFLECT PD3DReflect = NULL;
pD3DCompile PD3DCompile = NULL;
int d3dcompiler_dll_ref = 0;
HINSTANCE hD3DXDll = NULL;
D3DX11COMPILEFROMMEMORYTYPE PD3DX11CompileFromMemory = NULL;
D3DX11FILTERTEXTURETYPE PD3DX11FilterTexture = NULL;
D3DX11SAVETEXTURETOFILEATYPE PD3DX11SaveTextureToFileA = NULL;
D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW = NULL;
int d3dx_dll_ref = 0;
CREATEDXGIFACTORY PCreateDXGIFactory = NULL;
HINSTANCE hDXGIDll = NULL;
int dxgi_dll_ref = 0;
@ -91,6 +98,44 @@ HRESULT LoadD3D()
return S_OK;
}
HRESULT LoadD3DX()
{
if (d3dx_dll_ref++ > 0) return S_OK;
if (hD3DXDll) return S_OK;
// try to load D3DX11 first to check whether we have proper runtime support
// try to use the dll the backend was compiled against first - don't bother about debug runtimes
hD3DXDll = LoadLibraryA(D3DX11_DLL_A);
if (!hD3DXDll)
{
// if that fails, use the dll which should be available in every SDK which officially supports DX11.
hD3DXDll = LoadLibraryA("d3dx11_42.dll");
if (!hD3DXDll)
{
MessageBoxA(NULL, "Failed to load d3dx11_42.dll, update your DX11 runtime, please", "Critical error", MB_OK | MB_ICONERROR);
return E_FAIL;
}
else
{
NOTICE_LOG(VIDEO, "Successfully loaded d3dx11_42.dll. If you're having trouble, try updating your DX runtime first.");
}
}
PD3DX11CompileFromMemory = (D3DX11COMPILEFROMMEMORYTYPE)GetProcAddress(hD3DXDll, "D3DX11CompileFromMemory");
if (PD3DX11CompileFromMemory == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11CompileFromMemory!", "Critical error", MB_OK | MB_ICONERROR);
PD3DX11FilterTexture = (D3DX11FILTERTEXTURETYPE)GetProcAddress(hD3DXDll, "D3DX11FilterTexture");
if (PD3DX11FilterTexture == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11FilterTexture!", "Critical error", MB_OK | MB_ICONERROR);
PD3DX11SaveTextureToFileA = (D3DX11SAVETEXTURETOFILEATYPE)GetProcAddress(hD3DXDll, "D3DX11SaveTextureToFileA");
if (PD3DX11SaveTextureToFileA == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11SaveTextureToFileA!", "Critical error", MB_OK | MB_ICONERROR);
PD3DX11SaveTextureToFileW = (D3DX11SAVETEXTURETOFILEWTYPE)GetProcAddress(hD3DXDll, "D3DX11SaveTextureToFileW");
if (PD3DX11SaveTextureToFileW == NULL) MessageBoxA(NULL, "GetProcAddress failed for D3DX11SaveTextureToFileW!", "Critical error", MB_OK | MB_ICONERROR);
return S_OK;
}
HRESULT LoadD3DCompiler()
{
if (d3dcompiler_dll_ref++ > 0) return S_OK;
@ -132,6 +177,18 @@ void UnloadDXGI()
PCreateDXGIFactory = NULL;
}
void UnloadD3DX()
{
if (!d3dx_dll_ref) return;
if (--d3dx_dll_ref != 0) return;
if (hD3DXDll) FreeLibrary(hD3DXDll);
hD3DXDll = NULL;
PD3DX11FilterTexture = NULL;
PD3DX11SaveTextureToFileA = NULL;
PD3DX11SaveTextureToFileW = NULL;
}
void UnloadD3D()
{
if (!d3d_dll_ref) return;
@ -215,11 +272,13 @@ HRESULT Create(HWND wnd)
hr = LoadDXGI();
if (SUCCEEDED(hr)) hr = LoadD3D();
if (SUCCEEDED(hr)) hr = LoadD3DX();
if (SUCCEEDED(hr)) hr = LoadD3DCompiler();
if (FAILED(hr))
{
UnloadDXGI();
UnloadD3D();
UnloadD3DX();
UnloadD3DCompiler();
return hr;
}
@ -361,6 +420,7 @@ void Close()
// unload DLLs
UnloadD3D();
UnloadD3DX();
UnloadDXGI();
}