summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/Debugger/DebuggerPanel.cpp
blob: 095c0f9ebe99df906ec1d6d843fd7dfff96f3d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Copyright 2010 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <cstddef>
#include <string>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/msgdlg.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>

#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Core/ConfigManager.h"
#include "Core/CoreParameter.h"
#include "DolphinWX/WxUtils.h"
#include "DolphinWX/Debugger/DebuggerPanel.h"
#include "VideoCommon/Debugger.h"
#include "VideoCommon/TextureCacheBase.h"

GFXDebuggerPanel::GFXDebuggerPanel(wxWindow *parent, wxWindowID id, const wxPoint &position,
									const wxSize& size, long style, const wxString &title)
	: wxPanel(parent, id, position, size, style, title)
{
	g_pdebugger = this;

	CreateGUIControls();

	Bind(wxEVT_CLOSE_WINDOW, &GFXDebuggerPanel::OnClose, this);

	LoadSettings();
}

GFXDebuggerPanel::~GFXDebuggerPanel()
{
	g_pdebugger = nullptr;
	GFXDebuggerPauseFlag = false;
}

void GFXDebuggerPanel::OnClose(wxCloseEvent& event)
{
	// save the window position when we hide the window
	SaveSettings();

	event.Skip();
}

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

	// TODO: get the screen resolution and make limits from that
	if (GetPosition().x < 1000 &&
	    GetPosition().y < 1000 &&
	    GetSize().GetWidth() < 1000 &&
	    GetSize().GetHeight() < 1000)
	{
		IniFile::Section* video_window = file.GetOrCreateSection("VideoWindow");
		video_window->Set("x", GetPosition().x);
		video_window->Set("y", GetPosition().y);
		video_window->Set("w", GetSize().GetWidth());
		video_window->Set("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;
	int y = 100;
	int w = 100;
	int h = 100;

	IniFile::Section* video_window = file.GetOrCreateSection("VideoWindow");
	video_window->Get("x", &x, GetPosition().x);
	video_window->Get("y", &y, GetPosition().y);
	video_window->Get("w", &w, GetSize().GetWidth());
	video_window->Get("h", &h, GetSize().GetHeight());

	SetSize(x, y, w, h);
}

struct PauseEventMap
{
	PauseEvent event;
	const wxString ListStr;
};

static PauseEventMap* pauseEventMap;

void GFXDebuggerPanel::CreateGUIControls()
{
	static PauseEventMap map[] = {
		{NEXT_FRAME,                _("Frame")},
		{NEXT_FLUSH,                _("Flush")},

		{NEXT_PIXEL_SHADER_CHANGE,  _("Pixel Shader")},
		{NEXT_VERTEX_SHADER_CHANGE, _("Vertex Shader")},
		{NEXT_TEXTURE_CHANGE,       _("Texture")},
		{NEXT_NEW_TEXTURE,          _("New Texture")},

		{NEXT_XFB_CMD,              _("XFB Cmd")},
		{NEXT_EFB_CMD,              _("EFB Cmd")},

		{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")},

		{NEXT_SET_TLUT,             _("TLUT Cmd")},

		{NEXT_ERROR,                _("Error")}
	};
	pauseEventMap = map;
	const int numPauseEventMap = sizeof(map)/sizeof(PauseEventMap);

	// Basic settings
	CenterOnParent();

	m_pButtonPause = new wxButton(this, wxID_ANY, _("Pause"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Pause"));
	m_pButtonPause->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnPauseButton, this);

	m_pButtonPauseAtNext = new wxButton(this, wxID_ANY, _("Pause After"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Pause At Next"));
	m_pButtonPauseAtNext->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnPauseAtNextButton, this);

	m_pButtonPauseAtNextFrame = new wxButton(this, wxID_ANY, _("Go to Next Frame"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Next Frame"));
	m_pButtonPauseAtNextFrame->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnPauseAtNextFrameButton, this);

	m_pButtonCont = new wxButton(this, wxID_ANY, _("Continue"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Continue"));
	m_pButtonCont->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnContButton, this);

	m_pCount = new wxTextCtrl(this, wxID_ANY, "1", wxDefaultPosition, wxSize(50,25), wxTE_RIGHT, wxDefaultValidator, _("Count"));

	m_pPauseAtList = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(100,25), 0, nullptr,0,wxDefaultValidator, _("PauseAtList"));
	for (int i=0; i<numPauseEventMap; i++)
	{
		m_pPauseAtList->Append(pauseEventMap[i].ListStr);
	}
	m_pPauseAtList->SetSelection(0);

	m_pButtonDump = new wxButton(this, wxID_ANY, _("Dump"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Dump"));
	m_pButtonDump->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnDumpButton, this);

	m_pButtonUpdateScreen = new wxButton(this, wxID_ANY, _("Update Screen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Update Screen"));
	m_pButtonUpdateScreen->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnUpdateScreenButton, this);

	m_pButtonClearScreen = new wxButton(this, wxID_ANY, _("Clear Screen"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Clear Screen"));
	m_pButtonClearScreen->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnClearScreenButton, this);

	m_pButtonClearTextureCache = new wxButton(this, wxID_ANY, _("Clear Textures"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Clear Textures"));
	m_pButtonClearTextureCache->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnClearTextureCacheButton, this);

	m_pButtonClearVertexShaderCache = new wxButton(this, wxID_ANY, _("Clear V Shaders"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Clear V Shaders"));
	m_pButtonClearVertexShaderCache->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnClearVertexShaderCacheButton, this);

	m_pButtonClearPixelShaderCache = new wxButton(this, wxID_ANY, _("Clear P Shaders"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Clear P Shaders"));
	m_pButtonClearPixelShaderCache->Bind(wxEVT_BUTTON, &GFXDebuggerPanel::OnClearPixelShaderCacheButton, this);

	m_pDumpList = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(120,25), 0, nullptr, 0 ,wxDefaultValidator, _("DumpList"));
	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"));
	m_pDumpList->SetSelection(0);

	// Layout everything on m_MainPanel
	wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL);

	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);

	OnContinue();
}

void GFXDebuggerPanel::OnPause()
{
	m_pButtonDump->Enable();
	m_pDumpList->Enable();
	m_pButtonUpdateScreen->Enable();
	m_pButtonClearScreen->Enable();
	m_pButtonClearTextureCache->Enable();
	m_pButtonClearVertexShaderCache->Enable();
	m_pButtonClearPixelShaderCache->Enable();
}

void GFXDebuggerPanel::OnContinue()
{
	m_pButtonDump->Disable();
	m_pDumpList->Disable();
	m_pButtonUpdateScreen->Disable();
	m_pButtonClearScreen->Disable();
	m_pButtonClearTextureCache->Disable();
	m_pButtonClearVertexShaderCache->Disable();
	m_pButtonClearPixelShaderCache->Disable();
}


// 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)
{
	std::string dump_path = File::GetUserPath(D_DUMP_IDX) + "Debug/" +
		SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID + "/";
	if (!File::CreateFullPath(dump_path))
		return;

	switch (m_pDumpList->GetSelection())
	{
		case 0: // Pixel Shader
			DumpPixelShader(dump_path);
			break;

		case 1: // Vertex Shader
			DumpVertexShader(dump_path);
			break;

		case 2: // Pixel Shader Constants
			DumpPixelShaderConstants(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 3: // Vertex Shader Constants
			DumpVertexShaderConstants(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 4: // Textures
			DumpTextures(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 5: // Frame Buffer
			DumpFrameBuffer(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 6: // Geometry
			DumpGeometry(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 7: // Vertex Description
			DumpVertexDecl(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 8: // Vertex Matrices
			DumpMatrices(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;

		case 9: // Statistics
			DumpStats(dump_path);
			WxUtils::ShowErrorDialog(_("Not implemented"));
			break;
	}
}

void GFXDebuggerPanel::OnContButton(wxCommandEvent& event)
{
	GFXDebuggerToPauseAtNext = NOT_PAUSE;
	GFXDebuggerPauseFlag = false;
}

void GFXDebuggerPanel::OnClearScreenButton(wxCommandEvent& event)
{
	// TODO
	WxUtils::ShowErrorDialog(_("Not implemented"));
}

void GFXDebuggerPanel::OnClearTextureCacheButton(wxCommandEvent& event)
{
	TextureCache::Invalidate();
}

void GFXDebuggerPanel::OnClearVertexShaderCacheButton(wxCommandEvent& event)
{
	// TODO
	WxUtils::ShowErrorDialog(_("Not implemented"));
}

void GFXDebuggerPanel::OnClearPixelShaderCacheButton(wxCommandEvent& event)
{
	// TODO
	WxUtils::ShowErrorDialog(_("Not implemented"));
}

void GFXDebuggerPanel::OnUpdateScreenButton(wxCommandEvent& event)
{
	WxUtils::ShowErrorDialog(_("Not implemented"));
	GFXDebuggerUpdateScreen();
}