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:
parent
25efe443ea
commit
5abed9d5a4
|
@ -24,11 +24,6 @@
|
|||
#include "XFStructs.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
HINSTANCE hD3DXDll = NULL;
|
||||
D3DX11COMPILEFROMMEMORYTYPE PD3DX11CompileFromMemory = NULL;
|
||||
D3DX11FILTERTEXTURETYPE PD3DX11FilterTexture = NULL;
|
||||
|
@ -167,22 +162,22 @@ HRESULT Create(HWND wnd)
|
|||
return E_FAIL;
|
||||
}
|
||||
SetDebugObjectName((ID3D11DeviceChild*)context, "device context");
|
||||
factory->Release();
|
||||
output->Release();
|
||||
adapter->Release();
|
||||
SAFE_RELEASE(factory);
|
||||
SAFE_RELEASE(output);
|
||||
SAFE_RELEASE(adapter);
|
||||
|
||||
ID3D11Texture2D* buf;
|
||||
hr = swapchain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&buf);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
MessageBox(wnd, _T("Failed to get swapchain buffer"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
|
||||
device->Release();
|
||||
context->Release();
|
||||
swapchain->Release();
|
||||
SAFE_RELEASE(device);
|
||||
SAFE_RELEASE(context);
|
||||
SAFE_RELEASE(swapchain);
|
||||
return E_FAIL;
|
||||
}
|
||||
backbuf = new D3DTexture2D(buf, D3D11_BIND_RENDER_TARGET);
|
||||
buf->Release();
|
||||
SAFE_RELEASE(buf);
|
||||
CHECK(backbuf!=NULL, "Create back buffer texture");
|
||||
SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetTex(), "backbuffer texture");
|
||||
SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetRTV(), "backbuffer render target view");
|
||||
|
@ -255,8 +250,10 @@ unsigned int GetMaxTextureSize()
|
|||
|
||||
case D3D_FEATURE_LEVEL_9_2:
|
||||
case D3D_FEATURE_LEVEL_9_1:
|
||||
default:
|
||||
return 2048;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,13 +275,13 @@ void Reset()
|
|||
if (FAILED(hr))
|
||||
{
|
||||
MessageBox(hWnd, _T("Failed to get swapchain buffer"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
|
||||
device->Release();
|
||||
context->Release();
|
||||
swapchain->Release();
|
||||
SAFE_RELEASE(device);
|
||||
SAFE_RELEASE(context);
|
||||
SAFE_RELEASE(swapchain);
|
||||
return;
|
||||
}
|
||||
backbuf = new D3DTexture2D(buf, D3D11_BIND_RENDER_TARGET);
|
||||
buf->Release();
|
||||
SAFE_RELEASE(buf);
|
||||
CHECK(backbuf!=NULL, "Create back buffer texture");
|
||||
SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetTex(), "backbuffer texture");
|
||||
SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetRTV(), "backbuffer render target view");
|
||||
|
|
|
@ -66,7 +66,7 @@ D3DTexture2D* D3DTexture2D::Create(unsigned int width, unsigned int height, D3D1
|
|||
}
|
||||
|
||||
D3DTexture2D* ret = new D3DTexture2D(pTexture, bind);
|
||||
pTexture->Release();
|
||||
SAFE_RELEASE(pTexture);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ void D3DTexture2D::AddRef()
|
|||
|
||||
UINT D3DTexture2D::Release()
|
||||
{
|
||||
ref--;
|
||||
--ref;
|
||||
if (ref == 0)
|
||||
{
|
||||
delete this;
|
||||
|
@ -106,8 +106,8 @@ D3DTexture2D::D3DTexture2D(ID3D11Texture2D* texptr, D3D11_BIND_FLAG bind,
|
|||
|
||||
D3DTexture2D::~D3DTexture2D()
|
||||
{
|
||||
if (srv) srv->Release();
|
||||
if (rtv) rtv->Release();
|
||||
if (dsv) dsv->Release();
|
||||
tex->Release();
|
||||
SAFE_RELEASE(srv);
|
||||
SAFE_RELEASE(rtv);
|
||||
SAFE_RELEASE(dsv);
|
||||
SAFE_RELEASE(tex);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#include "CPMemory.h"
|
||||
#include "NativeVertexFormat.h"
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
class D3DVertexFormat : public NativeVertexFormat
|
||||
{
|
||||
D3D11_INPUT_ELEMENT_DESC m_elems[32];
|
||||
|
|
|
@ -93,13 +93,12 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions=""..\..\core\common\win32\release\common.lib""
|
||||
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib cg.lib cgD3D9.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="../../../Externals/Cg;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
DelayLoadDLLs="d3dx9_42.dll"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
|
@ -204,13 +203,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\..\Externals\Cg64;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
DelayLoadDLLs="d3dx9_42.dll"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
SubSystem="2"
|
||||
|
@ -305,13 +303,12 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions=""..\..\core\common\win32\debug\common.lib""
|
||||
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib cg.lib cgD3D9.lib vfw32.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
||||
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_VideoDX9D.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="../../../Externals/Cg;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
DelayLoadDLLs="d3dx9d_42.dll"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
RandomizedBaseAddress="1"
|
||||
|
@ -404,13 +401,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28ud.lib wxmsw28ud_core.lib"
|
||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9D.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\..\Externals\Cg64;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
DelayLoadDLLs="d3dx9d_42.dll"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
RandomizedBaseAddress="1"
|
||||
|
@ -513,14 +509,13 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib cg.lib cgD3D9.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9DF.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="../../../Externals/Cg;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
IgnoreDefaultLibraryNames=""
|
||||
DelayLoadDLLs="d3dx9_42.dll"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
RandomizedBaseAddress="1"
|
||||
|
@ -625,13 +620,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
AdditionalDependencies="comctl32.lib d3d9.lib winmm.lib vfw32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib"
|
||||
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9DF.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\..\Externals\Cg64;"..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)""
|
||||
GenerateManifest="false"
|
||||
DelayLoadDLLs="d3dx9_42.dll"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
|
||||
RandomizedBaseAddress="1"
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue