forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabVertices.cpp
489 lines (412 loc) · 11.4 KB
/
TabVertices.cpp
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "base/basictypes.h"
#include "Core/System.h"
#include "Windows/resource.h"
#include "Windows/GEDebugger/GEDebugger.h"
#include "Windows/GEDebugger/TabVertices.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/GPUState.h"
#include "GPU/GeDisasm.h"
#include "GPU/Common/GPUDebugInterface.h"
static const GenericListViewColumn vertexListCols[] = {
{ L"X", 0.1f },
{ L"Y", 0.1f },
{ L"Z", 0.1f },
{ L"U", 0.1f },
{ L"V", 0.1f },
{ L"Color", 0.1f },
{ L"NX", 0.1f },
{ L"NY", 0.1f },
{ L"NZ", 0.1f },
// TODO: weight, morph?
};
GenericListViewDef vertexListDef = {
vertexListCols, ARRAY_SIZE(vertexListCols), NULL, false
};
enum VertexListCols {
VERTEXLIST_COL_X,
VERTEXLIST_COL_Y,
VERTEXLIST_COL_Z,
VERTEXLIST_COL_U,
VERTEXLIST_COL_V,
VERTEXLIST_COL_COLOR,
VERTEXLIST_COL_NX,
VERTEXLIST_COL_NY,
VERTEXLIST_COL_NZ,
};
static const GenericListViewColumn matrixListCols[] = {
{ L"Name", 0.24f },
{ L"0", 0.19f },
{ L"1", 0.19f },
{ L"2", 0.19f },
{ L"3", 0.19f },
};
GenericListViewDef matrixListDef = {
matrixListCols, ARRAY_SIZE(matrixListCols), NULL, false
};
enum MatrixListCols {
MATRIXLIST_COL_NAME,
MATRIXLIST_COL_0,
MATRIXLIST_COL_1,
MATRIXLIST_COL_2,
MATRIXLIST_COL_3,
MATRIXLIST_COL_COUNT,
};
enum MatrixListRows {
MATRIXLIST_ROW_WORLD_0,
MATRIXLIST_ROW_WORLD_1,
MATRIXLIST_ROW_WORLD_2,
MATRIXLIST_ROW_VIEW_0,
MATRIXLIST_ROW_VIEW_1,
MATRIXLIST_ROW_VIEW_2,
MATRIXLIST_ROW_PROJ_0,
MATRIXLIST_ROW_PROJ_1,
MATRIXLIST_ROW_PROJ_2,
MATRIXLIST_ROW_PROJ_3,
MATRIXLIST_ROW_TGEN_0,
MATRIXLIST_ROW_TGEN_1,
MATRIXLIST_ROW_TGEN_2,
MATRIXLIST_ROW_BONE_0_0,
MATRIXLIST_ROW_BONE_0_1,
MATRIXLIST_ROW_BONE_0_2,
MATRIXLIST_ROW_BONE_1_0,
MATRIXLIST_ROW_BONE_1_1,
MATRIXLIST_ROW_BONE_1_2,
MATRIXLIST_ROW_BONE_2_0,
MATRIXLIST_ROW_BONE_2_1,
MATRIXLIST_ROW_BONE_2_2,
MATRIXLIST_ROW_BONE_3_0,
MATRIXLIST_ROW_BONE_3_1,
MATRIXLIST_ROW_BONE_3_2,
MATRIXLIST_ROW_BONE_4_0,
MATRIXLIST_ROW_BONE_4_1,
MATRIXLIST_ROW_BONE_4_2,
MATRIXLIST_ROW_BONE_5_0,
MATRIXLIST_ROW_BONE_5_1,
MATRIXLIST_ROW_BONE_5_2,
MATRIXLIST_ROW_BONE_6_0,
MATRIXLIST_ROW_BONE_6_1,
MATRIXLIST_ROW_BONE_6_2,
MATRIXLIST_ROW_BONE_7_0,
MATRIXLIST_ROW_BONE_7_1,
MATRIXLIST_ROW_BONE_7_2,
MATRIXLIST_ROW_COUNT,
};
CtrlVertexList::CtrlVertexList(HWND hwnd)
: GenericListControl(hwnd, vertexListDef), raw_(false) {
decoder = new VertexDecoder();
Update();
}
CtrlVertexList::~CtrlVertexList() {
delete decoder;
}
void CtrlVertexList::GetColumnText(wchar_t *dest, int row, int col) {
if (row < 0 || row >= rowCount_ ) {
wcscpy(dest, L"Invalid");
return;
}
if (!indices.empty()) {
if (row >= (int)indices.size()) {
swprintf(dest, L"Invalid indice %d", row);
return;
}
row = indices[row];
}
if (raw_) {
FormatVertColRaw(dest, row, col);
} else {
if (row >= (int)vertices.size()) {
swprintf(dest, L"Invalid vertex %d", row);
return;
}
FormatVertCol(dest, vertices[row], col);
}
}
void CtrlVertexList::FormatVertCol(wchar_t *dest, const GPUDebugVertex &vert, int col) {
switch (col) {
case VERTEXLIST_COL_X: swprintf(dest, L"%f", vert.x); break;
case VERTEXLIST_COL_Y: swprintf(dest, L"%f", vert.y); break;
case VERTEXLIST_COL_Z: swprintf(dest, L"%f", vert.z); break;
case VERTEXLIST_COL_U: swprintf(dest, L"%f", vert.u); break;
case VERTEXLIST_COL_V: swprintf(dest, L"%f", vert.v); break;
case VERTEXLIST_COL_COLOR:
swprintf(dest, L"%02x%02x%02x%02x", vert.c[0], vert.c[1], vert.c[2], vert.c[3]);
break;
case VERTEXLIST_COL_NX: swprintf(dest, L"%f", vert.nx); break;
case VERTEXLIST_COL_NY: swprintf(dest, L"%f", vert.ny); break;
case VERTEXLIST_COL_NZ: swprintf(dest, L"%f", vert.nz); break;
default:
wcscpy(dest, L"Invalid");
break;
}
}
void CtrlVertexList::FormatVertColRaw(wchar_t *dest, int row, int col) {
auto memLock = Memory::Lock();
if (!PSP_IsInited()) {
wcscpy(dest, L"Invalid");
return;
}
// We could use the vertex decoder and reader, but those already do some minor adjustments.
// There's only a few values - let's just go after them directly.
const u8 *vert = Memory::GetPointer(gpuDebug->GetVertexAddress()) + row * decoder->size;
const u8 *pos = vert + decoder->posoff;
const u8 *tc = vert + decoder->tcoff;
const u8 *color = vert + decoder->coloff;
switch (col) {
case VERTEXLIST_COL_X:
FormatVertColRawType(dest, pos, decoder->pos, 0);
break;
case VERTEXLIST_COL_Y:
FormatVertColRawType(dest, pos, decoder->pos, 1);
break;
case VERTEXLIST_COL_Z:
FormatVertColRawType(dest, pos, decoder->pos, 2);
break;
case VERTEXLIST_COL_U:
FormatVertColRawType(dest, tc, decoder->tc, 0);
break;
case VERTEXLIST_COL_V:
FormatVertColRawType(dest, tc, decoder->tc, 1);
break;
case VERTEXLIST_COL_COLOR:
FormatVertColRawColor(dest, color, decoder->col);
break;
default:
wcscpy(dest, L"Invalid");
break;
}
}
void CtrlVertexList::FormatVertColRawType(wchar_t *dest, const void *data, int type, int offset) {
switch (type) {
case 0:
wcscpy(dest, L"-");
break;
case 1: // 8-bit
swprintf(dest, L"%02x", ((const u8 *)data)[offset]);
break;
case 2: // 16-bit
swprintf(dest, L"%04x", ((const u16_le *)data)[offset]);
break;
case 3: // float
swprintf(dest, L"%f", ((const float *)data)[offset]);
break;
default:
wcscpy(dest, L"Invalid");
break;
}
}
void CtrlVertexList::FormatVertColRawColor(wchar_t *dest, const void *data, int type) {
switch (type) {
case GE_VTYPE_COL_NONE >> GE_VTYPE_COL_SHIFT:
wcscpy(dest, L"-");
break;
case GE_VTYPE_COL_565 >> GE_VTYPE_COL_SHIFT:
case GE_VTYPE_COL_5551 >> GE_VTYPE_COL_SHIFT:
case GE_VTYPE_COL_4444 >> GE_VTYPE_COL_SHIFT:
swprintf(dest, L"%04x", *(const u16_le *)data);
break;
case GE_VTYPE_COL_8888 >> GE_VTYPE_COL_SHIFT:
swprintf(dest, L"%08x", *(const u32_le *)data);
break;
default:
wcscpy(dest, L"Invalid");
break;
}
}
int CtrlVertexList::GetRowCount() {
auto memLock = Memory::Lock();
if (!PSP_IsInited()) {
return 0;
}
if (!gpuDebug || !Memory::IsValidAddress(gpuDebug->GetVertexAddress())) {
rowCount_ = 0;
return rowCount_;
}
// TODO: Maybe there are smarter ways? Also, is this the best place to recalc?
auto state = gpuDebug->GetGState();
rowCount_ = state.prim & 0xFFFF;
// Override if we're on a prim command.
DisplayList list;
if (gpuDebug->GetCurrentDisplayList(list)) {
u32 cmd = Memory::Read_U32(list.pc);
if ((cmd >> 24) == GE_CMD_PRIM) {
rowCount_ = cmd & 0xFFFF;
}
}
if (!gpuDebug->GetCurrentSimpleVertices(rowCount_, vertices, indices)) {
rowCount_ = 0;
}
VertexDecoderOptions options{};
decoder->SetVertexType(state.vertType, options);
return rowCount_;
}
TabVertices::TabVertices(HINSTANCE _hInstance, HWND _hParent)
: Dialog((LPCSTR)IDD_GEDBG_TAB_VERTICES, _hInstance, _hParent) {
values = new CtrlVertexList(GetDlgItem(m_hDlg, IDC_GEDBG_VERTICES));
}
TabVertices::~TabVertices() {
delete values;
}
void TabVertices::UpdateSize(WORD width, WORD height) {
struct Position {
int x,y;
int w,h;
};
Position position;
static const int borderMargin = 5;
static const int checkboxSpace = 22;
position.x = borderMargin;
position.y = borderMargin + checkboxSpace;
position.w = width - 2 * borderMargin;
position.h = height - 2 * borderMargin - checkboxSpace;
HWND handle = GetDlgItem(m_hDlg, IDC_GEDBG_VERTICES);
MoveWindow(handle, position.x, position.y, position.w, position.h, TRUE);
}
BOOL TabVertices::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG:
return TRUE;
case WM_SIZE:
UpdateSize(LOWORD(lParam), HIWORD(lParam));
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_GEDBG_RAWVERTS) {
values->SetRaw(IsDlgButtonChecked(m_hDlg, IDC_GEDBG_RAWVERTS) == BST_CHECKED);
values->Update();
}
return TRUE;
case WM_NOTIFY:
switch (wParam)
{
case IDC_GEDBG_VERTICES:
values->HandleNotify(lParam);
break;
}
break;
}
return FALSE;
}
CtrlMatrixList::CtrlMatrixList(HWND hwnd)
: GenericListControl(hwnd, matrixListDef) {
Update();
}
void CtrlMatrixList::GetColumnText(wchar_t *dest, int row, int col) {
if (!gpuDebug || row < 0 || row >= MATRIXLIST_ROW_COUNT || col < 0 || col >= MATRIXLIST_COL_COUNT) {
wcscpy(dest, L"Invalid");
return;
}
auto state = gpuDebug->GetGState();
if (row >= MATRIXLIST_ROW_BONE_0_0) {
int b = (row - MATRIXLIST_ROW_BONE_0_0) / 3;
int r = (row - MATRIXLIST_ROW_BONE_0_0) % 3;
int offset = (row - MATRIXLIST_ROW_BONE_0_0) * 4 + col - 1;
switch (col) {
case MATRIXLIST_COL_NAME:
swprintf(dest, L"Bone #%d row %d", b, r);
break;
default:
swprintf(dest, L"%f", state.boneMatrix[offset]);
break;
}
} else if (row >= MATRIXLIST_ROW_TGEN_0) {
int r = row - MATRIXLIST_ROW_TGEN_0;
int offset = r * 4 + col - 1;
switch (col) {
case MATRIXLIST_COL_NAME:
swprintf(dest, L"Texgen %d", r);
break;
default:
swprintf(dest, L"%f", state.tgenMatrix[offset]);
break;
}
} else if (row >= MATRIXLIST_ROW_PROJ_0) {
int r = row - MATRIXLIST_ROW_PROJ_0;
int offset = r * 4 + col - 1;
switch (col) {
case MATRIXLIST_COL_NAME:
swprintf(dest, L"Proj %d", r);
break;
default:
swprintf(dest, L"%f", state.projMatrix[offset]);
break;
}
} else if (row >= MATRIXLIST_ROW_VIEW_0) {
int r = row - MATRIXLIST_ROW_VIEW_0;
int offset = r * 4 + col - 1;
switch (col) {
case MATRIXLIST_COL_NAME:
swprintf(dest, L"View %d", r);
break;
default:
swprintf(dest, L"%f", state.viewMatrix[offset]);
break;
}
} else {
int r = row - MATRIXLIST_ROW_WORLD_0;
int offset = r * 4 + col - 1;
switch (col) {
case MATRIXLIST_COL_NAME:
swprintf(dest, L"World %d", r);
break;
default:
swprintf(dest, L"%f", state.worldMatrix[offset]);
break;
}
}
}
int CtrlMatrixList::GetRowCount() {
if (!gpuDebug) {
return 0;
}
return MATRIXLIST_ROW_COUNT;
}
TabMatrices::TabMatrices(HINSTANCE _hInstance, HWND _hParent)
: Dialog((LPCSTR)IDD_GEDBG_TAB_MATRICES, _hInstance, _hParent) {
values = new CtrlMatrixList(GetDlgItem(m_hDlg, IDC_GEDBG_MATRICES));
}
TabMatrices::~TabMatrices() {
delete values;
}
void TabMatrices::UpdateSize(WORD width, WORD height) {
struct Position {
int x,y;
int w,h;
};
Position position;
static const int borderMargin = 5;
position.x = borderMargin;
position.y = borderMargin;
position.w = width - 2 * borderMargin;
position.h = height - 2 * borderMargin;
HWND handle = GetDlgItem(m_hDlg, IDC_GEDBG_MATRICES);
MoveWindow(handle, position.x, position.y, position.w, position.h, TRUE);
}
BOOL TabMatrices::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG:
return TRUE;
case WM_SIZE:
UpdateSize(LOWORD(lParam), HIWORD(lParam));
return TRUE;
case WM_NOTIFY:
switch (wParam)
{
case IDC_GEDBG_MATRICES:
values->HandleNotify(lParam);
break;
}
break;
}
return FALSE;
}