mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-14 15:00:30 +02:00
Extract the vertex formatting code from the Windows GE Debugger
This commit is contained in:
1 parent
47c98a9135
commit
95b7db99ed
4 files changed
+140
-132
No files matched your search
+117
-1
@@ -1,10 +1,12 @@
|
||||
#include <cstdio>
|
||||
#include "Common/Common.h"
|
||||
|
||||
#include "Common/StringUtils.h"
|
||||
#include "GPU/Debugger/State.h"
|
||||
#include "GPU/GPU.h"
|
||||
#include "GPU/Common/GPUDebugInterface.h"
|
||||
#include "GPU/GeDisasm.h"
|
||||
#include "GPU/Common/VertexDecoderCommon.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
const TabStateRow g_stateFlagsRows[] = {
|
||||
{ "Lighting enable", GE_CMD_LIGHTINGENABLE, CMD_FMT_FLAG },
|
||||
@@ -716,3 +718,117 @@ void FormatStateRow(GPUDebugInterface *gpudebug, char *dest, size_t destSize, Cm
|
||||
strcat(dest, " (disabled)");
|
||||
}
|
||||
}
|
||||
|
||||
void FormatVertCol(char *dest, size_t destSize, const GPUDebugVertex &vert, int col) {
|
||||
switch (col) {
|
||||
case VERTEXLIST_COL_X: snprintf(dest, destSize, "%f", vert.x); break;
|
||||
case VERTEXLIST_COL_Y: snprintf(dest, destSize, "%f", vert.y); break;
|
||||
case VERTEXLIST_COL_Z: snprintf(dest, destSize, "%f", vert.z); break;
|
||||
case VERTEXLIST_COL_U: snprintf(dest, destSize, "%f", vert.u); break;
|
||||
case VERTEXLIST_COL_V: snprintf(dest, destSize, "%f", vert.v); break;
|
||||
case VERTEXLIST_COL_COLOR:
|
||||
snprintf(dest, destSize, "%02x%02x%02x%02x", vert.c[0], vert.c[1], vert.c[2], vert.c[3]);
|
||||
break;
|
||||
case VERTEXLIST_COL_NX: snprintf(dest, destSize, "%f", vert.nx); break;
|
||||
case VERTEXLIST_COL_NY: snprintf(dest, destSize, "%f", vert.ny); break;
|
||||
case VERTEXLIST_COL_NZ: snprintf(dest, destSize, "%f", vert.nz); break;
|
||||
|
||||
default:
|
||||
truncate_cpy(dest, destSize, "Invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void FormatVertColRawType(char *dest, size_t destSize, const void *data, int type, int offset);
|
||||
static void FormatVertColRawColor(char *dest, size_t destSize, const void *data, int type);
|
||||
|
||||
void FormatVertColRaw(VertexDecoder *decoder, char *dest, size_t destSize, int row, int col) {
|
||||
auto memLock = Memory::Lock();
|
||||
if (!PSP_IsInited()) {
|
||||
truncate_cpy(dest, destSize, "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;
|
||||
const u8 *norm = vert + decoder->nrmoff;
|
||||
|
||||
switch (col) {
|
||||
case VERTEXLIST_COL_X:
|
||||
FormatVertColRawType(dest, destSize, pos, decoder->pos, 0);
|
||||
break;
|
||||
case VERTEXLIST_COL_Y:
|
||||
FormatVertColRawType(dest, destSize, pos, decoder->pos, 1);
|
||||
break;
|
||||
case VERTEXLIST_COL_Z:
|
||||
FormatVertColRawType(dest, destSize, pos, decoder->pos, 2);
|
||||
break;
|
||||
case VERTEXLIST_COL_U:
|
||||
FormatVertColRawType(dest, destSize, tc, decoder->tc, 0);
|
||||
break;
|
||||
case VERTEXLIST_COL_V:
|
||||
FormatVertColRawType(dest, destSize, tc, decoder->tc, 1);
|
||||
break;
|
||||
case VERTEXLIST_COL_COLOR:
|
||||
FormatVertColRawColor(dest, destSize, color, decoder->col);
|
||||
break;
|
||||
|
||||
case VERTEXLIST_COL_NX: FormatVertColRawType(dest, destSize, norm, decoder->nrm, 0); break;
|
||||
case VERTEXLIST_COL_NY: FormatVertColRawType(dest, destSize, norm, decoder->nrm, 1); break;
|
||||
case VERTEXLIST_COL_NZ: FormatVertColRawType(dest, destSize, norm, decoder->nrm, 2); break;
|
||||
|
||||
default:
|
||||
truncate_cpy(dest, destSize, "Invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void FormatVertColRawType(char *dest, size_t destSize, const void *data, int type, int offset) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
truncate_cpy(dest, destSize, "-");
|
||||
break;
|
||||
|
||||
case 1: // 8-bit
|
||||
snprintf(dest, destSize, "%02x", ((const u8 *)data)[offset]);
|
||||
break;
|
||||
|
||||
case 2: // 16-bit
|
||||
snprintf(dest, destSize, "%04x", ((const u16_le *)data)[offset]);
|
||||
break;
|
||||
|
||||
case 3: // float
|
||||
snprintf(dest, destSize, "%f", ((const float *)data)[offset]);
|
||||
break;
|
||||
|
||||
default:
|
||||
truncate_cpy(dest, destSize, "Invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void FormatVertColRawColor(char *dest, size_t destSize, const void *data, int type) {
|
||||
switch (type) {
|
||||
case GE_VTYPE_COL_NONE >> GE_VTYPE_COL_SHIFT:
|
||||
truncate_cpy(dest, destSize, "-");
|
||||
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:
|
||||
snprintf(dest, destSize, "%04x", *(const u16_le *)data);
|
||||
break;
|
||||
|
||||
case GE_VTYPE_COL_8888 >> GE_VTYPE_COL_SHIFT:
|
||||
snprintf(dest, destSize, "%08x", *(const u32_le *)data);
|
||||
break;
|
||||
|
||||
default:
|
||||
truncate_cpy(dest, destSize, "Invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,18 @@ enum CmdFormatType {
|
||||
CMD_FMT_PATCHPRIMITIVE,
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
class GPUDebugInterface;
|
||||
|
||||
|
||||
@@ -70,4 +82,9 @@ extern const size_t g_stateLightingRowsSize;
|
||||
extern const size_t g_stateTextureRowsSize;
|
||||
extern const size_t g_stateSettingsRowsSize;
|
||||
|
||||
struct GPUDebugVertex;
|
||||
class VertexDecoder;
|
||||
|
||||
void FormatStateRow(GPUDebugInterface *debug, char *dest, size_t destSize, CmdFormatType fmt, u32 value, bool enabled, u32 otherValue, u32 otherValue2);
|
||||
void FormatVertCol(char *dest, size_t destSize, const GPUDebugVertex &vert, int col);
|
||||
void FormatVertColRaw(VertexDecoder *decoder, char *dest, size_t destSize, int row, int col);
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "GPU/Common/GPUDebugInterface.h"
|
||||
#include "GPU/Debugger/Breakpoints.h"
|
||||
#include "GPU/Debugger/Stepping.h"
|
||||
#include "GPU/Debugger/State.h"
|
||||
|
||||
static const GenericListViewColumn vertexListCols[] = {
|
||||
{ L"X", 0.1f },
|
||||
@@ -50,18 +51,6 @@ 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"", 0.03f },
|
||||
{ L"Name", 0.21f },
|
||||
@@ -146,133 +135,24 @@ void CtrlVertexList::GetColumnText(wchar_t *dest, size_t destSize, int row, int
|
||||
|
||||
if (!indices.empty()) {
|
||||
if (row >= (int)indices.size()) {
|
||||
swprintf(dest, destSize, L"Invalid indice %d", row);
|
||||
swprintf(dest, destSize, L"Invalid index %d", row);
|
||||
return;
|
||||
}
|
||||
row = indices[row];
|
||||
}
|
||||
|
||||
char temp[256];
|
||||
if (raw_) {
|
||||
FormatVertColRaw(dest, row, col);
|
||||
FormatVertColRaw(decoder, temp, sizeof(temp), row, col);
|
||||
} else {
|
||||
if (row >= (int)vertices.size()) {
|
||||
swprintf(dest, destSize, 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, 255, L"%f", vert.x); break;
|
||||
case VERTEXLIST_COL_Y: swprintf(dest, 255, L"%f", vert.y); break;
|
||||
case VERTEXLIST_COL_Z: swprintf(dest, 255, L"%f", vert.z); break;
|
||||
case VERTEXLIST_COL_U: swprintf(dest, 255, L"%f", vert.u); break;
|
||||
case VERTEXLIST_COL_V: swprintf(dest, 255, L"%f", vert.v); break;
|
||||
case VERTEXLIST_COL_COLOR:
|
||||
swprintf(dest, 255, L"%02x%02x%02x%02x", vert.c[0], vert.c[1], vert.c[2], vert.c[3]);
|
||||
break;
|
||||
case VERTEXLIST_COL_NX: swprintf(dest, 255, L"%f", vert.nx); break;
|
||||
case VERTEXLIST_COL_NY: swprintf(dest, 255, L"%f", vert.ny); break;
|
||||
case VERTEXLIST_COL_NZ: swprintf(dest, 255, 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;
|
||||
const u8 *norm = vert + decoder->nrmoff;
|
||||
|
||||
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;
|
||||
|
||||
case VERTEXLIST_COL_NX: FormatVertColRawType(dest, norm, decoder->nrm, 0); break;
|
||||
case VERTEXLIST_COL_NY: FormatVertColRawType(dest, norm, decoder->nrm, 1); break;
|
||||
case VERTEXLIST_COL_NZ: FormatVertColRawType(dest, norm, decoder->nrm, 2); 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, 255, L"%02x", ((const u8 *)data)[offset]);
|
||||
break;
|
||||
|
||||
case 2: // 16-bit
|
||||
swprintf(dest, 255, L"%04x", ((const u16_le *)data)[offset]);
|
||||
break;
|
||||
|
||||
case 3: // float
|
||||
swprintf(dest, 255, 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, 255, L"%04x", *(const u16_le *)data);
|
||||
break;
|
||||
|
||||
case GE_VTYPE_COL_8888 >> GE_VTYPE_COL_SHIFT:
|
||||
swprintf(dest, 255, L"%08x", *(const u32_le *)data);
|
||||
break;
|
||||
|
||||
default:
|
||||
wcscpy(dest, L"Invalid");
|
||||
break;
|
||||
FormatVertCol(temp, sizeof(temp), vertices[row], col);
|
||||
}
|
||||
ConvertUTF8ToWString(dest, destSize, temp);
|
||||
}
|
||||
|
||||
int CtrlVertexList::GetRowCount() {
|
||||
|
||||
@@ -40,11 +40,6 @@ protected:
|
||||
int GetRowCount() override;
|
||||
|
||||
private:
|
||||
void FormatVertCol(wchar_t *dest, const GPUDebugVertex &vert, int col);
|
||||
void FormatVertColRaw(wchar_t *dest, int row, int col);
|
||||
void FormatVertColRawType(wchar_t *dest, const void *data, int type, int offset);
|
||||
void FormatVertColRawColor(wchar_t *dest, const void *data, int type);
|
||||
|
||||
std::vector<GPUDebugVertex> vertices;
|
||||
std::vector<u16> indices;
|
||||
int rowCount_;
|
||||
|
||||
Reference in new issue
Block a user