2013-04-17 21:43:35 -06:00
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2010-12-05 07:15:36 -07:00
# include "IniFile.h"
# include "DebuggerPanel.h"
# include "FileUtil.h"
2011-01-30 18:28:32 -07:00
# include "../../Core/Src/ConfigManager.h"
2010-12-05 07:15:36 -07:00
# include "VideoConfig.h"
# include "TextureCacheBase.h"
# include "PixelShaderGen.h"
# include "VertexShaderGen.h"
# include "NativeVertexFormat.h"
BEGIN_EVENT_TABLE ( GFXDebuggerPanel , wxPanel )
EVT_CLOSE ( GFXDebuggerPanel : : OnClose )
EVT_BUTTON ( ID_PAUSE , GFXDebuggerPanel : : OnPauseButton )
EVT_BUTTON ( ID_PAUSE_AT_NEXT , GFXDebuggerPanel : : OnPauseAtNextButton )
EVT_BUTTON ( ID_PAUSE_AT_NEXT_FRAME , GFXDebuggerPanel : : OnPauseAtNextFrameButton )
EVT_BUTTON ( ID_CONT , GFXDebuggerPanel : : OnContButton )
EVT_BUTTON ( ID_DUMP , GFXDebuggerPanel : : OnDumpButton )
EVT_BUTTON ( ID_UPDATE_SCREEN , GFXDebuggerPanel : : OnUpdateScreenButton )
EVT_BUTTON ( ID_CLEAR_SCREEN , GFXDebuggerPanel : : OnClearScreenButton )
EVT_BUTTON ( ID_CLEAR_TEXTURE_CACHE , GFXDebuggerPanel : : OnClearTextureCacheButton )
EVT_BUTTON ( ID_CLEAR_VERTEX_SHADER_CACHE , GFXDebuggerPanel : : OnClearVertexShaderCacheButton )
EVT_BUTTON ( ID_CLEAR_PIXEL_SHADER_CACHE , GFXDebuggerPanel : : OnClearPixelShaderCacheButton )
END_EVENT_TABLE ( )
2011-02-16 05:09:39 -07:00
// From VideoCommon
extern GFXDebuggerBase * g_pdebugger ;
extern volatile bool GFXDebuggerPauseFlag ;
extern volatile PauseEvent GFXDebuggerToPauseAtNext ;
extern volatile int GFXDebuggerEventToPauseCount ;
2010-12-05 07:15:36 -07:00
GFXDebuggerPanel : : GFXDebuggerPanel ( wxWindow * parent , wxWindowID id , const wxPoint & position ,
const wxSize & size , long style , const wxString & title )
: wxPanel ( parent , id , position , size , style , title )
{
2011-01-30 21:36:49 -07:00
g_pdebugger = this ;
2010-12-05 07:15:36 -07:00
CreateGUIControls ( ) ;
LoadSettings ( ) ;
}
GFXDebuggerPanel : : ~ GFXDebuggerPanel ( )
{
2011-01-30 21:36:49 -07:00
g_pdebugger = NULL ;
2010-12-14 16:19:34 -07:00
GFXDebuggerPauseFlag = false ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : OnClose ( wxCloseEvent & event )
{
// save the window position when we hide the window
SaveSettings ( ) ;
2011-03-16 22:26:01 -06:00
event . Skip ( ) ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : SaveSettings ( ) const
{
IniFile file ;
file . Load ( File : : GetUserPath ( F_DEBUGGERCONFIG_IDX ) ) ;
// TODO: make this work when we close the entire program too, currently on total close we get
// weird values, perhaps because of some conflict with the rendering window
2013-04-07 23:47:51 -06:00
2010-12-05 07:15:36 -07:00
// TODO: get the screen resolution and make limits from that
if ( GetPosition ( ) . x < 1000 & & GetPosition ( ) . y < 1000
2013-04-07 23:16:50 -06:00
& & GetSize ( ) . GetWidth ( ) < 1000
2010-12-05 07:15:36 -07:00
& & GetSize ( ) . GetHeight ( ) < 1000 )
{
file . Set ( " VideoWindow " , " x " , GetPosition ( ) . x ) ;
file . Set ( " VideoWindow " , " y " , GetPosition ( ) . y ) ;
file . Set ( " VideoWindow " , " w " , GetSize ( ) . GetWidth ( ) ) ;
file . Set ( " VideoWindow " , " h " , GetSize ( ) . GetHeight ( ) ) ;
}
file . Save ( File : : GetUserPath ( F_DEBUGGERCONFIG_IDX ) ) ;
}
void GFXDebuggerPanel : : LoadSettings ( )
{
IniFile file ;
file . Load ( File : : GetUserPath ( F_DEBUGGERCONFIG_IDX ) ) ;
int x = 100 , y = 100 , w = 100 , h = 100 ;
file . Get ( " VideoWindow " , " x " , & x , GetPosition ( ) . x ) ;
file . Get ( " VideoWindow " , " y " , & y , GetPosition ( ) . y ) ;
file . Get ( " VideoWindow " , " w " , & w , GetSize ( ) . GetWidth ( ) ) ;
file . Get ( " VideoWindow " , " h " , & h , GetSize ( ) . GetHeight ( ) ) ;
SetSize ( x , y , w , h ) ;
}
struct PauseEventMap
{
PauseEvent event ;
const wxString ListStr ;
} ;
static PauseEventMap pauseEventMap [ ] = {
2011-01-04 21:35:46 -07:00
{ NEXT_FRAME , _ ( " Frame " ) } ,
{ NEXT_FLUSH , _ ( " Flush " ) } ,
2010-12-05 07:15:36 -07:00
2011-01-04 21:35:46 -07:00
{ NEXT_PIXEL_SHADER_CHANGE , _ ( " Pixel Shader " ) } ,
{ NEXT_VERTEX_SHADER_CHANGE , _ ( " Vertex Shader " ) } ,
{ NEXT_TEXTURE_CHANGE , _ ( " Texture " ) } ,
{ NEXT_NEW_TEXTURE , _ ( " New Texture " ) } ,
2010-12-05 07:15:36 -07:00
2011-01-04 21:35:46 -07:00
{ NEXT_XFB_CMD , _ ( " XFB Cmd " ) } ,
{ NEXT_EFB_CMD , _ ( " EFB Cmd " ) } ,
2010-12-05 07:15:36 -07:00
2011-01-04 21:35:46 -07:00
{ NEXT_MATRIX_CMD , _ ( " Matrix Cmd " ) } ,
{ NEXT_VERTEX_CMD , _ ( " Vertex Cmd " ) } ,
{ NEXT_TEXTURE_CMD , _ ( " Texture Cmd " ) } ,
{ NEXT_LIGHT_CMD , _ ( " Light Cmd " ) } ,
{ NEXT_FOG_CMD , _ ( " Fog Cmd " ) } ,
2010-12-05 07:15:36 -07:00
2011-01-04 21:35:46 -07:00
{ NEXT_SET_TLUT , _ ( " TLUT Cmd " ) } ,
2010-12-05 07:15:36 -07:00
2011-01-05 10:56:08 -07:00
{ NEXT_ERROR , _ ( " Error " ) }
2010-12-05 07:15:36 -07:00
} ;
static const int numPauseEventMap = sizeof ( pauseEventMap ) / sizeof ( PauseEventMap ) ;
void GFXDebuggerPanel : : CreateGUIControls ( )
{
// Basic settings
CenterOnParent ( ) ;
2011-07-01 14:59:57 -06:00
m_pButtonPause = new wxButton ( this , ID_PAUSE , _ ( " Pause " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Pause " ) ) ;
m_pButtonPauseAtNext = new wxButton ( this , ID_PAUSE_AT_NEXT , _ ( " Pause After " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Pause At Next " ) ) ;
m_pButtonPauseAtNextFrame = new wxButton ( this , ID_PAUSE_AT_NEXT_FRAME , _ ( " Go to Next Frame " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Next Frame " ) ) ;
m_pButtonCont = new wxButton ( this , ID_CONT , _ ( " Continue " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Continue " ) ) ;
2010-12-05 07:15:36 -07:00
2011-07-01 14:59:57 -06:00
m_pCount = new wxTextCtrl ( this , ID_COUNT , wxT ( " 1 " ) , wxDefaultPosition , wxSize ( 50 , 25 ) , wxTE_RIGHT , wxDefaultValidator , _ ( " Count " ) ) ;
2010-12-05 07:15:36 -07:00
2011-07-01 14:59:57 -06:00
m_pPauseAtList = new wxChoice ( this , ID_PAUSE_AT_LIST , wxDefaultPosition , wxSize ( 100 , 25 ) , 0 , NULL , 0 , wxDefaultValidator , _ ( " PauseAtList " ) ) ;
2010-12-05 07:15:36 -07:00
for ( int i = 0 ; i < numPauseEventMap ; i + + )
{
m_pPauseAtList - > Append ( pauseEventMap [ i ] . ListStr ) ;
}
m_pPauseAtList - > SetSelection ( 0 ) ;
2011-07-01 14:59:57 -06:00
m_pButtonDump = new wxButton ( this , ID_DUMP , _ ( " Dump " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Dump " ) ) ;
m_pButtonUpdateScreen = new wxButton ( this , ID_UPDATE_SCREEN , _ ( " Update Screen " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Update Screen " ) ) ;
m_pButtonClearScreen = new wxButton ( this , ID_CLEAR_SCREEN , _ ( " Clear Screen " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Clear Screen " ) ) ;
m_pButtonClearTextureCache = new wxButton ( this , ID_CLEAR_TEXTURE_CACHE , _ ( " Clear Textures " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Clear Textures " ) ) ;
m_pButtonClearVertexShaderCache = new wxButton ( this , ID_CLEAR_VERTEX_SHADER_CACHE , _ ( " Clear V Shaders " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Clear V Shaders " ) ) ;
m_pButtonClearPixelShaderCache = new wxButton ( this , ID_CLEAR_PIXEL_SHADER_CACHE , _ ( " Clear P Shaders " ) , wxDefaultPosition , wxDefaultSize , 0 , wxDefaultValidator , _ ( " Clear P Shaders " ) ) ;
2011-01-04 21:35:46 -07:00
2011-07-01 14:59:57 -06:00
m_pDumpList = new wxChoice ( this , ID_DUMP_LIST , wxDefaultPosition , wxSize ( 120 , 25 ) , 0 , NULL , 0 , wxDefaultValidator , _ ( " DumpList " ) ) ;
2011-01-04 21:35:46 -07:00
m_pDumpList - > Insert ( _ ( " Pixel Shader " ) , 0 ) ;
m_pDumpList - > Append ( _ ( " Vertex Shader " ) ) ;
m_pDumpList - > Append ( _ ( " Pixel Shader Constants " ) ) ;
m_pDumpList - > Append ( _ ( " Vertex Shader Constants " ) ) ;
m_pDumpList - > Append ( _ ( " Textures " ) ) ;
m_pDumpList - > Append ( _ ( " Frame Buffer " ) ) ;
m_pDumpList - > Append ( _ ( " Geometry data " ) ) ;
m_pDumpList - > Append ( _ ( " Vertex Description " ) ) ;
m_pDumpList - > Append ( _ ( " Vertex Matrices " ) ) ;
m_pDumpList - > Append ( _ ( " Statistics " ) ) ;
2010-12-05 07:15:36 -07:00
m_pDumpList - > SetSelection ( 0 ) ;
// Layout everything on m_MainPanel
wxBoxSizer * sMain = new wxBoxSizer ( wxVERTICAL ) ;
2011-07-01 14:59:57 -06:00
wxStaticBoxSizer * const pFlowCtrlBox = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Flow Control " ) ) ;
wxBoxSizer * const pPauseAtNextSzr = new wxBoxSizer ( wxHORIZONTAL ) ;
pFlowCtrlBox - > Add ( m_pButtonPause ) ;
pPauseAtNextSzr - > Add ( m_pButtonPauseAtNext ) ;
pPauseAtNextSzr - > Add ( m_pCount ) ;
pPauseAtNextSzr - > Add ( m_pPauseAtList ) ;
pFlowCtrlBox - > Add ( pPauseAtNextSzr ) ;
pFlowCtrlBox - > Add ( m_pButtonPauseAtNextFrame ) ;
pFlowCtrlBox - > Add ( m_pButtonCont ) ;
wxStaticBoxSizer * const pDebugBox = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Debugging " ) ) ;
wxBoxSizer * const pDumpSzr = new wxBoxSizer ( wxHORIZONTAL ) ;
pDumpSzr - > Add ( m_pButtonDump ) ;
pDumpSzr - > Add ( m_pDumpList ) ;
pDebugBox - > Add ( pDumpSzr ) ;
wxGridSizer * const pDbgGrid = new wxGridSizer ( 2 , 5 , 5 ) ;
pDbgGrid - > Add ( m_pButtonUpdateScreen ) ;
pDbgGrid - > Add ( m_pButtonClearScreen ) ;
pDbgGrid - > Add ( m_pButtonClearTextureCache ) ;
pDbgGrid - > Add ( m_pButtonClearVertexShaderCache ) ;
pDbgGrid - > Add ( m_pButtonClearPixelShaderCache ) ;
pDebugBox - > Add ( pDbgGrid ) ;
sMain - > Add ( pFlowCtrlBox , 0 , 0 , 5 ) ;
sMain - > Add ( pDebugBox , 0 , 0 , 5 ) ;
SetSizerAndFit ( sMain ) ;
2010-12-05 07:15:36 -07:00
OnContinue ( ) ;
}
void GFXDebuggerPanel : : OnPause ( )
{
m_pButtonDump - > Enable ( true ) ;
2011-07-01 14:59:57 -06:00
m_pDumpList - > Enable ( true ) ;
2010-12-05 07:15:36 -07:00
m_pButtonUpdateScreen - > Enable ( true ) ;
m_pButtonClearScreen - > Enable ( true ) ;
m_pButtonClearTextureCache - > Enable ( true ) ;
m_pButtonClearVertexShaderCache - > Enable ( true ) ;
m_pButtonClearPixelShaderCache - > Enable ( true ) ;
}
void GFXDebuggerPanel : : OnContinue ( )
{
m_pButtonDump - > Enable ( false ) ;
2011-07-01 14:59:57 -06:00
m_pDumpList - > Enable ( false ) ;
2010-12-05 07:15:36 -07:00
m_pButtonUpdateScreen - > Enable ( false ) ;
m_pButtonClearScreen - > Enable ( false ) ;
m_pButtonClearTextureCache - > Enable ( false ) ;
m_pButtonClearVertexShaderCache - > Enable ( false ) ;
m_pButtonClearPixelShaderCache - > Enable ( false ) ;
}
// General settings
void GFXDebuggerPanel : : GeneralSettings ( wxCommandEvent & event )
{
SaveSettings ( ) ;
}
void GFXDebuggerPanel : : OnPauseButton ( wxCommandEvent & event )
{
GFXDebuggerPauseFlag = true ;
}
void GFXDebuggerPanel : : OnPauseAtNextButton ( wxCommandEvent & event )
{
GFXDebuggerPauseFlag = false ;
GFXDebuggerToPauseAtNext = pauseEventMap [ m_pPauseAtList - > GetSelection ( ) ] . event ;
wxString val = m_pCount - > GetValue ( ) ;
long value ;
if ( val . ToLong ( & value ) )
GFXDebuggerEventToPauseCount = value ;
else
GFXDebuggerEventToPauseCount = 1 ;
}
void GFXDebuggerPanel : : OnPauseAtNextFrameButton ( wxCommandEvent & event )
{
GFXDebuggerPauseFlag = false ;
GFXDebuggerToPauseAtNext = NEXT_FRAME ;
GFXDebuggerEventToPauseCount = 1 ;
}
void GFXDebuggerPanel : : OnDumpButton ( wxCommandEvent & event )
{
2011-02-28 13:40:15 -07:00
std : : string dump_path = File : : GetUserPath ( D_DUMP_IDX ) + " Debug/ " +
SConfig : : GetInstance ( ) . m_LocalCoreStartupParameter . m_strUniqueID + " / " ;
2011-02-28 20:06:14 -07:00
if ( ! File : : CreateFullPath ( dump_path ) )
2010-12-14 16:19:34 -07:00
return ;
2010-12-05 07:15:36 -07:00
switch ( m_pDumpList - > GetSelection ( ) )
{
case 0 : // Pixel Shader
2011-02-28 13:40:15 -07:00
DumpPixelShader ( dump_path . c_str ( ) ) ;
2010-12-05 07:15:36 -07:00
break ;
case 1 : // Vertex Shader
2011-02-28 13:40:15 -07:00
DumpVertexShader ( dump_path . c_str ( ) ) ;
2010-12-05 07:15:36 -07:00
break ;
case 2 : // Pixel Shader Constants
2011-02-28 13:40:15 -07:00
DumpPixelShaderConstants ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 3 : // Vertex Shader Constants
2011-02-28 13:40:15 -07:00
DumpVertexShaderConstants ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 4 : // Textures
2011-02-28 13:40:15 -07:00
DumpTextures ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 5 : // Frame Buffer
2011-02-28 13:40:15 -07:00
DumpFrameBuffer ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 6 : // Geometry
2011-02-28 13:40:15 -07:00
DumpGeometry ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 7 : // Vertex Description
2011-02-28 13:40:15 -07:00
DumpVertexDecl ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 8 : // Vertex Matrices
2011-02-28 13:40:15 -07:00
DumpMatrices ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
case 9 : // Statistics
2011-02-28 13:40:15 -07:00
DumpStats ( dump_path . c_str ( ) ) ;
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
break ;
}
}
void GFXDebuggerPanel : : OnContButton ( wxCommandEvent & event )
{
GFXDebuggerToPauseAtNext = NOT_PAUSE ;
GFXDebuggerPauseFlag = false ;
}
void GFXDebuggerPanel : : OnClearScreenButton ( wxCommandEvent & event )
{
// TODO
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : OnClearTextureCacheButton ( wxCommandEvent & event )
{
2012-05-28 03:37:14 -06:00
TextureCache : : Invalidate ( ) ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : OnClearVertexShaderCacheButton ( wxCommandEvent & event )
{
// TODO
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : OnClearPixelShaderCacheButton ( wxCommandEvent & event )
{
// TODO
2011-01-05 10:56:08 -07:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
}
void GFXDebuggerPanel : : OnUpdateScreenButton ( wxCommandEvent & event )
{
2011-07-01 14:59:57 -06:00
wxMessageBox ( _ ( " Not implemented " ) , _ ( " Error " ) , wxOK ) ;
2010-12-05 07:15:36 -07:00
GFXDebuggerUpdateScreen ( ) ;
}