mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
Dependency cleanup in DX9.
Dynamically load a d3dx9 dll at runtime (I tested Dolphin with the first d3dx9 dll and it even worked fine there). Should fix the flood of users asking why they can't select the DX9 plugin :P Compilers should be able to stop bundling cgD3D9.dll now. Minor changes in DX11. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5890 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -19,6 +19,13 @@
|
||||
#include "VideoConfig.h"
|
||||
#include "Render.h"
|
||||
#include "XFStructs.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
// D3DX
|
||||
HINSTANCE hD3DXDll = NULL;
|
||||
D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA = NULL;
|
||||
D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA = NULL;
|
||||
D3DXCOMPILESHADERTYPE PD3DXCompileShader = NULL;
|
||||
|
||||
namespace D3D
|
||||
{
|
||||
@ -250,6 +257,74 @@ void Enumerate()
|
||||
}
|
||||
}
|
||||
|
||||
// dynamically picks one of the available d3dx9 dlls and loads it.
|
||||
// we're first trying to load the dll Dolphin was compiled with, otherwise the most up-to-date one
|
||||
HRESULT LoadD3DX9()
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
hD3DXDll = LoadLibraryA(StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION).c_str());
|
||||
if (hD3DXDll != NULL)
|
||||
{
|
||||
NOTICE_LOG(VIDEO, "Successfully loaded %s.", StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION).c_str());
|
||||
hr = S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if that fails, try loading older dlls (no need to look for newer ones)
|
||||
for (unsigned int num = D3DX_SDK_VERSION-1; num >= 24; --num)
|
||||
{
|
||||
hD3DXDll = LoadLibraryA(StringFromFormat("d3dx9_%d.dll", num).c_str());
|
||||
if (hD3DXDll != NULL)
|
||||
{
|
||||
NOTICE_LOG(VIDEO, "Successfully loaded %s. If you're having trouble, try updating your DX runtime first.", StringFromFormat("d3dx9_%d.dll", num).c_str());
|
||||
hr = S_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (FAILED(hr))
|
||||
{
|
||||
MessageBoxA(NULL, "Failed to load any D3DX9 dll, update your DX9 runtime, please", "Critical error", MB_OK | MB_ICONERROR);
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
PD3DXCompileShader = (D3DXCOMPILESHADERTYPE)GetProcAddress(hD3DXDll, "D3DXCompileShader");
|
||||
if (PD3DXCompileShader == NULL)
|
||||
{
|
||||
MessageBoxA(NULL, "GetProcAddress failed for D3DXCompileShader!", "Critical error", MB_OK | MB_ICONERROR);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
PD3DXSaveSurfaceToFileA = (D3DXSAVESURFACETOFILEATYPE)GetProcAddress(hD3DXDll, "D3DXSaveSurfaceToFileA");
|
||||
if (PD3DXSaveSurfaceToFileA == NULL)
|
||||
{
|
||||
MessageBoxA(NULL, "GetProcAddress failed for D3DXSaveSurfaceToFileA!", "Critical error", MB_OK | MB_ICONERROR);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
PD3DXSaveTextureToFileA = (D3DXSAVETEXTURETOFILEATYPE)GetProcAddress(hD3DXDll, "D3DXSaveTextureToFileA");
|
||||
if (PD3DXSaveTextureToFileA == NULL)
|
||||
{
|
||||
MessageBoxA(NULL, "GetProcAddress failed for D3DXSaveTextureToFileA!", "Critical error", MB_OK | MB_ICONERROR);
|
||||
goto fail;
|
||||
}
|
||||
return S_OK;
|
||||
|
||||
fail:
|
||||
FreeLibrary(hD3DXDll);
|
||||
PD3DXCompileShader = NULL;
|
||||
PD3DXSaveSurfaceToFileA = NULL;
|
||||
PD3DXSaveTextureToFileA = NULL;
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
void UnloadD3DX9()
|
||||
{
|
||||
FreeLibrary(hD3DXDll);
|
||||
PD3DXCompileShader = NULL;
|
||||
PD3DXSaveSurfaceToFileA = NULL;
|
||||
PD3DXSaveTextureToFileA = NULL;
|
||||
}
|
||||
|
||||
HRESULT Create(int adapter, HWND wnd, int _resolution, int aa_mode, bool auto_depth)
|
||||
{
|
||||
hWnd = wnd;
|
||||
@ -257,7 +332,11 @@ HRESULT Create(int adapter, HWND wnd, int _resolution, int aa_mode, bool auto_de
|
||||
resolution = _resolution;
|
||||
auto_depth_stencil = auto_depth;
|
||||
cur_adapter = adapter;
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
|
||||
HRESULT hr = LoadD3DX9();
|
||||
if (FAILED(hr)) return hr;
|
||||
|
||||
InitPP(adapter, resolution, aa_mode, &d3dpp);
|
||||
|
||||
if (FAILED(D3D->CreateDevice(
|
||||
@ -303,6 +382,8 @@ HRESULT Create(int adapter, HWND wnd, int _resolution, int aa_mode, bool auto_de
|
||||
|
||||
void Close()
|
||||
{
|
||||
UnloadD3DX9();
|
||||
|
||||
if (back_buffer_z)
|
||||
back_buffer_z->Release();
|
||||
back_buffer_z = NULL;
|
||||
|
@ -141,4 +141,19 @@ int GetNumAdapters();
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
// Used to not require the SDK and runtime versions to match:
|
||||
// Linking with d3dx9.lib makes the most recent d3dx9_xx.dll of the
|
||||
// compiler's SDK an actually unnecessary requirement.
|
||||
// Add any d3dx9 functions which you want to use here and load them in LoadD3DX9()
|
||||
typedef HRESULT (WINAPI* D3DXSAVESURFACETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DSURFACE9, CONST PALETTEENTRY*, CONST RECT*);
|
||||
typedef HRESULT (WINAPI* D3DXSAVETEXTURETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DBASETEXTURE9, CONST PALETTEENTRY*);
|
||||
typedef HRESULT (WINAPI* D3DXCOMPILESHADERTYPE)(LPCSTR, UINT, CONST D3DXMACRO*, LPD3DXINCLUDE, LPCSTR, LPCSTR, DWORD, LPD3DXBUFFER*, LPD3DXBUFFER*, LPD3DXCONSTANTTABLE*);
|
||||
|
||||
extern D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA;
|
||||
extern D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA;
|
||||
extern D3DXCOMPILESHADERTYPE PD3DXCompileShader;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -40,7 +40,7 @@ bool CompileVertexShader(const char *code, int len, u8 **bytecode, int *bytecode
|
||||
//try to compile
|
||||
LPD3DXBUFFER shaderBuffer = 0;
|
||||
LPD3DXBUFFER errorBuffer = 0;
|
||||
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", D3D::VertexShaderVersionString(),
|
||||
HRESULT hr = PD3DXCompileShader(code, len, 0, 0, "main", D3D::VertexShaderVersionString(),
|
||||
0, &shaderBuffer, &errorBuffer, 0);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
@ -89,7 +89,7 @@ bool CompilePixelShader(const char *code, int len, u8 **bytecode, int *bytecodel
|
||||
// Someone:
|
||||
// For some reason, I had this kind of errors : "Shader uses texture addressing operations
|
||||
// in a dependency chain that is too complex for the target shader model (ps_2_0) to handle."
|
||||
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", D3D::PixelShaderVersionString(),
|
||||
HRESULT hr = PD3DXCompileShader(code, len, 0, 0, "main", D3D::PixelShaderVersionString(),
|
||||
0, &shaderBuffer, &errorBuffer, 0);
|
||||
|
||||
if (FAILED(hr))
|
||||
|
@ -1116,7 +1116,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
PanicAlert("Error dumping surface data.");
|
||||
}
|
||||
hr = D3DXSaveSurfaceToFileA(s_sScreenshotName, D3DXIFF_PNG, ScreenShootMEMSurface, NULL, dst_rect.AsRECT());
|
||||
hr = PD3DXSaveSurfaceToFileA(s_sScreenshotName, D3DXIFF_PNG, ScreenShootMEMSurface, NULL, dst_rect.AsRECT());
|
||||
if(FAILED(hr))
|
||||
{
|
||||
PanicAlert("Error saving screen.");
|
||||
|
@ -388,7 +388,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
|
||||
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir, uniqueId, texHash, tex_format);
|
||||
|
||||
if (!File::Exists(szTemp))
|
||||
D3DXSaveTextureToFileA(szTemp,D3DXIFF_PNG,entry.texture,0);
|
||||
PD3DXSaveTextureToFileA(szTemp,D3DXIFF_PNG,entry.texture,0);
|
||||
}
|
||||
|
||||
INCSTAT(stats.numTexturesCreated);
|
||||
|
Reference in New Issue
Block a user