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
{
2011-01-31 01:28:32 +00:00
unsigned int VideoBackend : : PeekMessages ( )
2008-12-08 05:25:12 +00:00
{
MSG msg ;
while ( PeekMessage ( & msg , 0 , 0 , 0 , PM_REMOVE ) )
{
if ( msg . message = = WM_QUIT )
return FALSE ;
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
return TRUE ;
}
2011-01-31 01:28:32 +00:00
void VideoBackend : : UpdateFPSDisplay ( const char * text )
2008-12-08 05:25:12 +00:00
{
2011-01-23 01:07:53 +00:00
TCHAR temp [ 512 ] ;
2011-08-21 21:30:19 +00:00
swprintf_s ( temp , sizeof ( temp ) / sizeof ( TCHAR ) , _T ( " %hs | DX9 | %hs " ) , scm_rev_str , text ) ;
2011-12-19 23:13:26 +00:00
EmuWindow : : SetWindowText ( temp ) ;
2008-12-08 05:25:12 +00:00
}
2011-01-31 01:28:32 +00:00
std : : string VideoBackend : : GetName ( )
2010-05-23 02:29:23 +00:00
{
2013-05-01 13:51:43 +00:00
return " DX9 " ;
2008-12-08 05:25:12 +00:00
}
2013-03-20 23:14:14 +00:00
std : : string VideoBackend : : GetDisplayName ( )
{
2013-08-11 14:55:13 +00:00
return " Direct3D9 (deprecated) " ;
2013-03-20 23:14:14 +00:00
}
2010-11-22 22:17:35 +00:00
void InitBackendInfo ( )
2008-12-08 05:25:12 +00:00
{
2011-05-31 20:16:59 +00:00
DX9 : : D3D : : Init ( ) ;
2013-03-31 23:02:13 +00:00
D3DCAPS9 device_caps = DX9 : : D3D : : GetCaps ( ) ;
const int shaderModel = ( ( device_caps . PixelShaderVersion > > 8 ) & 0xFF ) ;
2011-06-10 19:16:09 +00:00
const int maxConstants = ( shaderModel < 3 ) ? 32 : ( ( shaderModel < 4 ) ? 224 : 65536 ) ;
2013-03-28 23:08:51 +00:00
g_Config . backend_info . APIType = shaderModel < 3 ? API_D3D9_SM20 : API_D3D9_SM30 ;
2011-03-21 05:46:33 +00:00
g_Config . backend_info . bUseRGBATextures = false ;
2013-02-18 16:14:56 +00:00
g_Config . backend_info . bUseMinimalMipCount = true ;
2010-11-24 17:13:12 +00:00
g_Config . backend_info . bSupports3DVision = true ;
2013-03-29 13:27:33 +00:00
g_Config . backend_info . bSupportsPrimitiveRestart = false ; // TODO: figure out if it does
2013-03-31 23:02:13 +00:00
g_Config . backend_info . bSupportsSeparateAlphaFunction = device_caps . PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND ;
2013-04-01 00:15:58 +00:00
// Dual source blend disabled by default until a proper method to test for support is found
2013-03-31 23:02:13 +00:00
g_Config . backend_info . bSupportsDualSourceBlend = false ;
2010-12-27 21:56:20 +00:00
g_Config . backend_info . bSupportsFormatReinterpretation = true ;
2011-01-09 14:13:24 +00:00
g_Config . backend_info . bSupportsPixelLighting = C_PLIGHTS + 40 < = maxConstants & & C_PMATERIALS + 4 < = maxConstants ;
2013-07-22 10:02:16 +00:00
g_Config . backend_info . bSupportsEarlyZ = false ;
2010-06-13 19:41:07 +00:00
2010-11-15 09:54:07 +00:00
// adapters
2010-11-22 22:17:35 +00:00
g_Config . backend_info . Adapters . clear ( ) ;
2011-01-29 20:16:51 +00:00
for ( int i = 0 ; i < DX9 : : D3D : : GetNumAdapters ( ) ; + + i )
g_Config . backend_info . Adapters . push_back ( DX9 : : D3D : : GetAdapter ( i ) . ident . Description ) ;
2010-11-15 09:54:07 +00:00
// aamodes
2010-11-22 22:17:35 +00:00
g_Config . backend_info . AAModes . clear ( ) ;
2011-01-29 20:16:51 +00:00
if ( g_Config . iAdapter < DX9 : : D3D : : GetNumAdapters ( ) )
2010-11-15 09:54:07 +00:00
{
2011-01-29 20:16:51 +00:00
const DX9 : : D3D : : Adapter & adapter = DX9 : : D3D : : GetAdapter ( g_Config . iAdapter ) ;
2010-11-15 09:54:07 +00:00
2010-11-29 16:16:48 +00:00
for ( int i = 0 ; i < ( int ) adapter . aa_levels . size ( ) ; + + i )
2010-11-21 14:47:28 +00:00
g_Config . backend_info . AAModes . push_back ( adapter . aa_levels [ i ] . name ) ;
2010-11-15 09:54:07 +00:00
}
2011-02-05 02:13:33 +00:00
// Clear ppshaders string vector
g_Config . backend_info . PPShaders . clear ( ) ;
2010-11-15 09:54:07 +00:00
2011-01-29 20:16:51 +00:00
DX9 : : D3D : : Shutdown ( ) ;
2011-05-31 20:16:59 +00:00
}
void VideoBackend : : ShowConfig ( void * parent )
{
# if defined(HAVE_WX) && HAVE_WX
InitBackendInfo ( ) ;
VideoConfigDiag diag ( ( wxWindow * ) parent , _trans ( " Direct3D9 " ) , " gfx_dx9 " ) ;
diag . ShowModal ( ) ;
2010-11-22 22:17:35 +00:00
# endif
2008-12-08 05:25:12 +00:00
}
2011-02-25 21:14:13 +00:00
bool VideoBackend : : Initialize ( void * & window_handle )
2008-12-08 05:25:12 +00:00
{
2012-01-02 10:20:22 +00:00
InitializeShared ( ) ;
2010-11-22 22:17:35 +00:00
InitBackendInfo ( ) ;
2008-12-08 05:25:12 +00:00
frameCount = 0 ;
2009-09-13 17:46:33 +00:00
2011-04-25 20:06:45 +00:00
g_Config . Load ( ( File : : GetUserPath ( D_CONFIG_IDX ) + " gfx_dx9.ini " ) . c_str ( ) ) ;
g_Config . GameIniLoad ( SConfig : : GetInstance ( ) . m_LocalCoreStartupParameter . m_strGameIni . c_str ( ) ) ;
2011-05-31 20:16:59 +00:00
g_Config . UpdateProjectionHack ( ) ;
g_Config . VerifyValidity ( ) ;
2010-01-20 07:47:41 +00:00
UpdateActiveConfig ( ) ;
2010-09-28 02:15:02 +00:00
2011-02-25 21:14:13 +00:00
window_handle = ( void * ) EmuWindow : : Create ( ( HWND ) window_handle , GetModuleHandle ( 0 ) , _T ( " Loading - Please wait. " ) ) ;
if ( window_handle = = NULL )
2009-09-13 17:46:33 +00:00
{
ERROR_LOG ( VIDEO , " An error has occurred while trying to create the window. " ) ;
2011-02-25 21:14:13 +00:00
return false ;
2009-09-13 17:46:33 +00:00
}
2011-01-29 20:16:51 +00:00
else if ( FAILED ( DX9 : : D3D : : Init ( ) ) )
2009-09-13 17:46:33 +00:00
{
2010-05-23 02:29:23 +00:00
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 ) ;
2011-02-25 21:14:13 +00:00
return false ;
2009-09-13 17:46:33 +00:00
}
2010-01-20 07:47:41 +00:00
2011-02-14 02:18:03 +00:00
s_BackendInitialized = true ;
2011-02-25 21:14:13 +00:00
2011-03-02 15:13:13 +00:00
return true ;
}
void VideoBackend : : Video_Prepare ( )
{
2010-01-01 03:55:39 +00:00
// Better be safe...
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
2010-03-14 18:57:50 +00:00
s_swapRequested = FALSE ;
2010-09-28 02:15:02 +00:00
// internal interfaces
2011-01-31 01:28:32 +00:00
g_vertex_manager = new VertexManager ;
2013-04-04 15:53:06 +00:00
g_perf_query = new PerfQuery ;
2012-10-20 13:22:15 +00:00
g_renderer = new Renderer ;
2013-04-04 15:53:06 +00:00
g_texture_cache = new TextureCache ;
2010-09-28 02:15:02 +00:00
// VideoCommon
BPInit ( ) ;
2008-12-08 05:25:12 +00:00
Fifo_Init ( ) ;
2013-04-08 17:39:43 +00:00
IndexGenerator : : Init ( ) ;
2008-12-25 20:07:13 +00:00
VertexLoaderManager : : Init ( ) ;
2008-12-08 05:25:12 +00:00
OpcodeDecoder_Init ( ) ;
2009-03-07 23:20:14 +00:00
VertexShaderManager : : Init ( ) ;
PixelShaderManager : : Init ( ) ;
2010-05-23 02:29:23 +00:00
CommandProcessor : : Init ( ) ;
PixelEngine : : Init ( ) ;
2013-04-01 00:15:58 +00:00
DLCache : : Init ( ) ;
2011-02-14 02:18:03 +00:00
// Notify the core that the video backend is ready
2011-03-15 23:09:12 +00:00
Host_Message ( WM_USER_CREATE ) ;
2008-12-08 05:25:12 +00:00
}
2011-01-31 01:28:32 +00:00
void VideoBackend : : Shutdown ( )
2008-12-08 05:25:12 +00:00
{
2011-02-14 02:18:03 +00:00
s_BackendInitialized = false ;
2010-09-28 02:15:02 +00:00
2013-02-26 15:42:32 +00:00
// TODO: should be in Video_Cleanup
2011-03-02 15:13:13 +00:00
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 ;
2013-04-04 15:53:06 +00:00
delete g_perf_query ;
2012-10-20 13:22:15 +00:00
delete g_vertex_manager ;
2011-03-02 15:13:13 +00:00
g_renderer = NULL ;
2012-06-21 12:21:16 +00:00
g_texture_cache = NULL ;
2011-03-02 15:13:13 +00:00
}
2011-01-31 01:28:32 +00:00
D3D : : Shutdown ( ) ;
2008-12-08 05:25:12 +00:00
}
2011-01-31 01:28:32 +00:00
2013-02-26 15:42:32 +00:00
void VideoBackend : : Video_Cleanup ( ) {
}
2011-01-31 01:28:32 +00:00
}