GSdx: Cleanups -- moved the new detection code to GSDevice11.cpp, where it (more or less) belongs.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2964 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-05-07 14:19:54 +00:00
parent e17d65cda6
commit d6eeb6a438
4 changed files with 113 additions and 93 deletions

View File

@ -22,8 +22,93 @@
#include "stdafx.h" #include "stdafx.h"
#include "GSdx.h" #include "GSdx.h"
#include "GSDevice11.h" #include "GSDevice11.h"
#include "GSUtil.h"
#include "resource.h" #include "resource.h"
// ---------------------------------------------------------------------------------
// DX11 Detection (includes DXGI detection and dynamic library method bindings)
// ---------------------------------------------------------------------------------
// Code 'Borrowed' from Microsoft's DXGI sources -- Modified to suit our needs. --air
static IDXGIFactory* m_DXGIFactory = NULL;
static bool m_D3D11Available = false;
static HMODULE s_hModD3D11 = NULL;
static FnPtr_D3D11CreateDevice s_DynamicD3D11CreateDevice = NULL;
static HMODULE s_hModDXGI = NULL;
static FnPtr_CreateDXGIFactory s_DynamicCreateDXGIFactory = NULL;
static bool DXUT_EnsureD3D11APIs( void )
{
// If any function pointer is non-NULL, this function has already been called.
if( s_DynamicD3D11CreateDevice )
return true;
s_hModDXGI = LoadLibrary( _T("dxgi.dll") );
if( s_hModDXGI )
{
s_DynamicCreateDXGIFactory = (FnPtr_CreateDXGIFactory)GetProcAddress( s_hModDXGI, "CreateDXGIFactory" );
}
// If DXGI isn't installed then this system isn't even capable of DX11 support; so no point
// in checking for DX11 DLLs.
if( s_DynamicCreateDXGIFactory == NULL ) return false;
// Check for DX11 DLLs.
s_hModD3D11 = LoadLibrary( _T("d3d11.dll") );
if( s_hModD3D11 == NULL ) LoadLibrary( _T("d3d11_beta.dll") );
if( s_hModD3D11 != NULL )
{
s_DynamicD3D11CreateDevice = (FnPtr_D3D11CreateDevice)GetProcAddress( s_hModD3D11, "D3D11CreateDevice" );
}
return ( s_DynamicD3D11CreateDevice != NULL );
}
static bool WINAPI DXUT_Dynamic_CreateDXGIFactory( REFIID rInterface, void ** ppOut )
{
if( !DXUT_EnsureD3D11APIs() ) return false;
return s_DynamicCreateDXGIFactory( rInterface, ppOut ) == S_OK;
}
static bool DXUTDelayLoadDXGI()
{
if( m_DXGIFactory == NULL )
{
DXUT_Dynamic_CreateDXGIFactory( __uuidof( IDXGIFactory ), (LPVOID*)&m_DXGIFactory );
m_D3D11Available = ( m_DXGIFactory != NULL );
}
return m_D3D11Available;
}
static void* GetDX11Proc( const char* methodname )
{
if( !DXUT_EnsureD3D11APIs() ) return NULL;
return GetProcAddress( s_hModD3D11, methodname );
}
bool GSUtil::IsDirect3D11Available()
{
return DXUTDelayLoadDXGI();
//return m_D3D11Available;
}
void GSUtil::UnloadDynamicLibraries()
{
if( s_hModD3D11 ) FreeLibrary(s_hModD3D11);
if( s_hModDXGI ) FreeLibrary(s_hModDXGI);
s_hModD3D11 = NULL;
s_hModDXGI = NULL;
}
GSDevice11::GSDevice11() GSDevice11::GSDevice11()
{ {
memset(&m_state, 0, sizeof(m_state)); memset(&m_state, 0, sizeof(m_state));
@ -865,8 +950,8 @@ void GSDevice11::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector
vp.TopLeftX = 0; vp.TopLeftX = 0;
vp.TopLeftY = 0; vp.TopLeftY = 0;
vp.Width = rt->GetWidth(); vp.Width = (FLOAT)rt->GetWidth();
vp.Height = rt->GetHeight(); vp.Height = (FLOAT)rt->GetHeight();
vp.MinDepth = 0.0f; vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f; vp.MaxDepth = 1.0f;
@ -965,7 +1050,7 @@ HRESULT GSDevice11::CompileShader(uint32 id, const string& entry, D3D11_SHADER_M
CComPtr<ID3D11Blob> shader, error; CComPtr<ID3D11Blob> shader, error;
hr = D3DX11CompileFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), NULL, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), 0, 0, NULL, &shader, &error, NULL); hr = D3DX11CompileFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), NULL, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), 0, 0, NULL, &shader, &error, NULL);
if(error) if(error)
{ {
printf("%s\n", (const char*)error->GetBufferPointer()); printf("%s\n", (const char*)error->GetBufferPointer());

View File

@ -24,6 +24,25 @@
#include "GSDeviceDX.h" #include "GSDeviceDX.h"
#include "GSTexture11.h" #include "GSTexture11.h"
typedef HRESULT (WINAPI * FnPtr_CreateDXGIFactory)(REFIID, void ** );
typedef HRESULT (WINAPI * FnPtr_D3D11CreateDevice)( IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT, ID3D11Device**, D3D_FEATURE_LEVEL *, ID3D11DeviceContext**);
typedef HRESULT (WINAPI * FnPtr_D3D11CreateDeviceAndSwapChain) (
__in IDXGIAdapter *pAdapter,
__in D3D_DRIVER_TYPE DriverType,
__in HMODULE Software,
__in UINT Flags,
__in const D3D_FEATURE_LEVEL *pFeatureLevels,
__in UINT FeatureLevels,
__in UINT SDKVersion,
__in const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
__out IDXGISwapChain **ppSwapChain,
__out ID3D11Device **ppDevice,
__out D3D_FEATURE_LEVEL *pFeatureLevel,
__out ID3D11DeviceContext **ppImmediateContext
);
struct GSVertexShader11 struct GSVertexShader11
{ {
CComPtr<ID3D11VertexShader> vs; CComPtr<ID3D11VertexShader> vs;

View File

@ -190,98 +190,10 @@ bool GSUtil::CheckSSE()
} }
typedef IDirect3D9* (WINAPI * LPDIRECT3DCREATE9) (UINT); typedef IDirect3D9* (WINAPI * LPDIRECT3DCREATE9) (UINT);
typedef HRESULT (WINAPI * LPCREATEDXGIFACTORY)(REFIID, void ** );
typedef HRESULT (WINAPI * LPD3D11CREATEDEVICE)( IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT, ID3D11Device**, D3D_FEATURE_LEVEL *, ID3D11DeviceContext**);
// ---------------------------------------------------------------------------------
// DX10/11 Detection (includes DXGI detection and dynamic library method bindings)
// ---------------------------------------------------------------------------------
// Code 'Borrowed' from DXGI sources -- Modified to suit our needs. --air
static IDXGIFactory* m_DXGIFactory = NULL;
static bool m_D3D11Available = false;
static HMODULE s_hModD3D9 = NULL; static HMODULE s_hModD3D9 = NULL;
static LPDIRECT3DCREATE9 s_DynamicDirect3DCreate9 = NULL; static LPDIRECT3DCREATE9 s_DynamicDirect3DCreate9 = NULL;
/*static LPD3DPERF_BEGINEVENT s_DynamicD3DPERF_BeginEvent = NULL;
static LPD3DPERF_ENDEVENT s_DynamicD3DPERF_EndEvent = NULL;
static LPD3DPERF_SETMARKER s_DynamicD3DPERF_SetMarker = NULL;
static LPD3DPERF_SETREGION s_DynamicD3DPERF_SetRegion = NULL;
static LPD3DPERF_QUERYREPEATFRAME s_DynamicD3DPERF_QueryRepeatFrame = NULL;
static LPD3DPERF_SETOPTIONS s_DynamicD3DPERF_SetOptions = NULL;
static LPD3DPERF_GETSTATUS s_DynamicD3DPERF_GetStatus = NULL;
*/
static HMODULE s_hModD3D11 = NULL;
static LPD3D11CREATEDEVICE s_DynamicD3D11CreateDevice = NULL;
static HMODULE s_hModDXGI = NULL;
static LPCREATEDXGIFACTORY s_DynamicCreateDXGIFactory = NULL;
static bool DXUT_EnsureD3D11APIs( void )
{
// If any function pointer is non-NULL, this function has already been called.
if( s_DynamicD3D11CreateDevice )
return true;
s_hModDXGI = LoadLibrary( _T("dxgi.dll") );
if( s_hModDXGI )
{
s_DynamicCreateDXGIFactory = (LPCREATEDXGIFACTORY)GetProcAddress( s_hModDXGI, "CreateDXGIFactory" );
}
// If DXGI isn't installed then this system isn't even capable of DX11 support; so no point
// in checking for DX11 DLLs.
if( s_DynamicCreateDXGIFactory == NULL ) return false;
// Check for DX11 DLLs.
s_hModD3D11 = LoadLibrary( _T("d3d11.dll") );
if( s_hModD3D11 == NULL ) LoadLibrary( _T("d3d11_beta.dll") );
if( s_hModD3D11 != NULL )
{
s_DynamicD3D11CreateDevice = (LPD3D11CREATEDEVICE)GetProcAddress( s_hModD3D11, "D3D11CreateDevice" );
}
return ( s_DynamicD3D11CreateDevice != NULL );
}
static bool WINAPI DXUT_Dynamic_CreateDXGIFactory( REFIID rInterface, void ** ppOut )
{
if( !DXUT_EnsureD3D11APIs() ) return false;
return s_DynamicCreateDXGIFactory( rInterface, ppOut ) == S_OK;
}
static bool DXUTDelayLoadDXGI()
{
if( m_DXGIFactory == NULL )
{
DXUT_Dynamic_CreateDXGIFactory( __uuidof( IDXGIFactory ), (LPVOID*)&m_DXGIFactory );
m_D3D11Available = ( m_DXGIFactory != NULL );
}
return m_D3D11Available;
}
bool GSUtil::IsDirect3D11Available()
{
return DXUTDelayLoadDXGI();
//return m_D3D11Available;
}
void GSUtil::UnloadDynamicLibraries()
{
if( s_hModD3D11 ) FreeLibrary(s_hModD3D11);
if( s_hModDXGI ) FreeLibrary(s_hModDXGI);
s_hModD3D11 = NULL;
s_hModDXGI = NULL;
}
char* GSUtil::GetLibName() char* GSUtil::GetLibName()
{ {

View File

@ -36,9 +36,13 @@ public:
static bool CheckDirectX(); static bool CheckDirectX();
static bool CheckSSE(); static bool CheckSSE();
static bool IsDirect3D11Available();
static void UnloadDynamicLibraries(); static void UnloadDynamicLibraries();
static char* GetLibName(); static char* GetLibName();
// These should probably be located more closely to their respective DX9/DX11 driver files,
// and not here in GSUtil (which should be DirectX independent, generally speaking) --air
static void* GetDX9Proc( const char* methodname );
static bool IsDirect3D11Available();
}; };