2013-04-18 03:29:41 +00:00
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2008-12-08 05:25:12 +00:00
# include "Common.h"
2009-09-04 17:29:16 +00:00
# include "Atomic.h"
2009-07-12 21:58:32 +00:00
# include "Thread.h"
# include "LogManager.h"
2008-12-08 05:25:12 +00:00
2010-06-13 19:41:07 +00:00
# if defined(HAVE_WX) && HAVE_WX
2010-11-15 09:54:07 +00:00
# include "VideoConfigDiag.h"
2010-06-13 19:41:07 +00:00
# endif // HAVE_WX
2009-09-02 06:33:41 +00:00
# if defined(HAVE_WX) && HAVE_WX
2011-02-13 06:06:32 +00:00
# include "Debugger/DebuggerPanel.h"
2009-09-02 06:33:41 +00:00
# endif // HAVE_WX
2010-11-18 02:21:26 +00:00
# include "MainBase.h"
2008-12-08 05:25:12 +00:00
# include "main.h"
2009-09-13 09:23:30 +00:00
# include "VideoConfig.h"
2008-12-08 05:25:12 +00:00
# include "Fifo.h"
# include "OpcodeDecoding.h"
# include "TextureCache.h"
2009-06-22 09:31:30 +00:00
# include "BPStructs.h"
2008-12-08 05:25:12 +00:00
# include "VertexManager.h"
2010-11-18 02:21:26 +00:00
# include "FramebufferManager.h"
2008-12-25 20:07:13 +00:00
# include "VertexLoaderManager.h"
2009-03-07 23:20:14 +00:00
# include "VertexShaderManager.h"
# include "PixelShaderManager.h"
# include "VertexShaderCache.h"
# include "PixelShaderCache.h"
2009-10-10 21:19:39 +00:00
# include "CommandProcessor.h"
# include "PixelEngine.h"
2009-09-03 20:37:35 +00:00
# include "OnScreenDisplay.h"
2008-12-08 05:25:12 +00:00
# include "D3DTexture.h"
# include "D3DUtil.h"
# include "EmuWindow.h"
# include "VideoState.h"
2012-12-23 07:25:11 +00:00
# include "Render.h"
2010-08-29 23:08:56 +00:00
# include "DLCache.h"
2013-04-08 17:39:43 +00:00
# include "IndexGenerator.h"
2011-01-14 15:09:30 +00:00
# include "IniFile.h"
2011-01-31 01:28:32 +00:00
# include "Core.h"
2011-03-15 23:09:12 +00:00
# include "Host.h"
2009-09-20 03:29:43 +00:00
2011-01-31 01:28:32 +00:00
# include "ConfigManager.h"
# include "VideoBackend.h"
2013-04-04 15:53:06 +00:00
# include "PerfQuery.h"
2009-07-02 17:45:09 +00:00
2011-01-31 01:28:32 +00:00
namespace DX9
2011-01-14 15:09:30 +00:00
{
2013-08-15 18:40:57 +00:00
unsigned int VideoBackend : : PeekMessages ( )
{
MSG msg ;
while ( PeekMessage ( & msg , 0 , 0 , 0 , PM_REMOVE ) )
{
if ( msg . message = = WM_QUIT )
return FALSE ;
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
return TRUE ;
}
void VideoBackend : : UpdateFPSDisplay ( const char * text )
{
TCHAR temp [ 512 ] ;
swprintf_s ( temp , sizeof ( temp ) / sizeof ( TCHAR ) , _T ( " %hs | DX9 | %hs " ) , scm_rev_str , text ) ;
EmuWindow : : SetWindowText ( temp ) ;
}
std : : string VideoBackend : : GetName ( )
{
return " DX9 " ;
}
std : : string VideoBackend : : GetDisplayName ( )
{
return " Direct3D9 (deprecated) " ;
}
void InitBackendInfo ( )
{
DX9 : : D3D : : Init ( ) ;
D3DCAPS9 device_caps = DX9 : : D3D : : GetCaps ( ) ;
const int shaderModel = ( ( device_caps . PixelShaderVersion > > 8 ) & 0xFF ) ;
const int maxConstants = ( shaderModel < 3 ) ? 32 : ( ( shaderModel < 4 ) ? 224 : 65536 ) ;
g_Config . backend_info . APIType = shaderModel < 3 ? API_D3D9_SM20 : API_D3D9_SM30 ;
g_Config . backend_info . bUseRGBATextures = false ;
g_Config . backend_info . bUseMinimalMipCount = true ;
g_Config . backend_info . bSupports3DVision = true ;
g_Config . backend_info . bSupportsPrimitiveRestart = false ; // D3D9 does not support primitive restart
g_Config . backend_info . bSupportsSeparateAlphaFunction = device_caps . PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND ;
// Dual source blend disabled by default until a proper method to test for support is found
g_Config . backend_info . bSupports3DVision = true ;
OSVERSIONINFO info ;
ZeroMemory ( & info , sizeof ( OSVERSIONINFO ) ) ;
info . dwOSVersionInfoSize = sizeof ( OSVERSIONINFO ) ;
if ( GetVersionEx ( & info ) )
{
// dual source blending is only supported in windows 7 o newer. sorry xp users
// we cannot test for device caps because most drivers just declare the minimun caps
// and don't expose their support for some functionalities
g_Config . backend_info . bSupportsDualSourceBlend = g_Config . backend_info . bSupportsSeparateAlphaFunction & & ( info . dwPlatformId = = VER_PLATFORM_WIN32_NT ) & & ( ( info . dwMajorVersion > 6 ) | | ( ( info . dwMajorVersion = = 6 ) & & info . dwMinorVersion > = 1 ) ) ;
}
else
{
g_Config . backend_info . bSupportsDualSourceBlend = false ;
}
g_Config . backend_info . bSupportsFormatReinterpretation = true ;
g_Config . backend_info . bSupportsPixelLighting = C_PLIGHTS + 40 < = maxConstants & & C_PMATERIALS + 4 < = maxConstants ;
g_Config . backend_info . bSupportsEarlyZ = false ;
// adapters
g_Config . backend_info . Adapters . clear ( ) ;
for ( int i = 0 ; i < DX9 : : D3D : : GetNumAdapters ( ) ; + + i )
g_Config . backend_info . Adapters . push_back ( DX9 : : D3D : : GetAdapter ( i ) . ident . Description ) ;
// aamodes
g_Config . backend_info . AAModes . clear ( ) ;
if ( g_Config . iAdapter < DX9 : : D3D : : GetNumAdapters ( ) )
{
const DX9 : : D3D : : Adapter & adapter = DX9 : : D3D : : GetAdapter ( g_Config . iAdapter ) ;
for ( int i = 0 ; i < ( int ) adapter . aa_levels . size ( ) ; + + i )
g_Config . backend_info . AAModes . push_back ( adapter . aa_levels [ i ] . name ) ;
}
// Clear ppshaders string vector
g_Config . backend_info . PPShaders . clear ( ) ;
DX9 : : D3D : : Shutdown ( ) ;
}
void VideoBackend : : ShowConfig ( void * parent )
{
2011-05-31 20:16:59 +00:00
# if defined(HAVE_WX) && HAVE_WX
2013-08-15 18:40:57 +00:00
InitBackendInfo ( ) ;
VideoConfigDiag diag ( ( wxWindow * ) parent , _trans ( " Direct3D9 " ) , " gfx_dx9 " ) ;
diag . ShowModal ( ) ;
2010-11-22 22:17:35 +00:00
# endif
2013-08-15 18:40:57 +00:00
}
bool VideoBackend : : Initialize ( void * & window_handle )
{
InitializeShared ( ) ;
InitBackendInfo ( ) ;
frameCount = 0 ;
g_Config . Load ( ( File : : GetUserPath ( D_CONFIG_IDX ) + " gfx_dx9.ini " ) . c_str ( ) ) ;
2013-09-23 06:39:14 +00:00
g_Config . GameIniLoad ( ) ;
2013-08-15 18:40:57 +00:00
g_Config . UpdateProjectionHack ( ) ;
g_Config . VerifyValidity ( ) ;
// as only some driver/hardware configurations support dual source blending only enable it if is
// configured by user
g_Config . backend_info . bSupportsDualSourceBlend & = g_Config . bForceDualSourceBlend ;
UpdateActiveConfig ( ) ;
window_handle = ( void * ) EmuWindow : : Create ( ( HWND ) window_handle , GetModuleHandle ( 0 ) , _T ( " Loading - Please wait. " ) ) ;
if ( window_handle = = NULL )
{
ERROR_LOG ( VIDEO , " An error has occurred while trying to create the window. " ) ;
return false ;
}
else if ( FAILED ( DX9 : : D3D : : Init ( ) ) )
{
MessageBox ( GetActiveWindow ( ) , _T ( " Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed. " ) , _T ( " Fatal Error " ) , MB_ICONERROR | MB_OK ) ;
return false ;
}
s_BackendInitialized = true ;
return true ;
}
void VideoBackend : : Video_Prepare ( )
{
// Better be safe...
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
s_swapRequested = FALSE ;
// internal interfaces
g_vertex_manager = new VertexManager ;
g_perf_query = new PerfQuery ;
g_renderer = new Renderer ;
g_texture_cache = new TextureCache ;
// VideoCommon
BPInit ( ) ;
Fifo_Init ( ) ;
IndexGenerator : : Init ( ) ;
VertexLoaderManager : : Init ( ) ;
OpcodeDecoder_Init ( ) ;
VertexShaderManager : : Init ( ) ;
PixelShaderManager : : Init ( ) ;
CommandProcessor : : Init ( ) ;
PixelEngine : : Init ( ) ;
DLCache : : Init ( ) ;
// Notify the core that the video backend is ready
Host_Message ( WM_USER_CREATE ) ;
}
void VideoBackend : : Shutdown ( )
{
s_BackendInitialized = false ;
// TODO: should be in Video_Cleanup
if ( g_renderer )
{
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
s_swapRequested = FALSE ;
// VideoCommon
DLCache : : Shutdown ( ) ;
Fifo_Shutdown ( ) ;
CommandProcessor : : Shutdown ( ) ;
PixelShaderManager : : Shutdown ( ) ;
VertexShaderManager : : Shutdown ( ) ;
OpcodeDecoder_Shutdown ( ) ;
VertexLoaderManager : : Shutdown ( ) ;
// internal interfaces
PixelShaderCache : : Shutdown ( ) ;
VertexShaderCache : : Shutdown ( ) ;
delete g_texture_cache ;
delete g_renderer ;
delete g_perf_query ;
delete g_vertex_manager ;
g_renderer = NULL ;
g_texture_cache = NULL ;
}
D3D : : Shutdown ( ) ;
}
void VideoBackend : : Video_Cleanup ( ) {
}
2013-02-26 15:42:32 +00:00
2011-01-31 01:28:32 +00:00
}