Skip to content

Commit

Permalink
Refactor the GE state viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 10, 2024
1 parent 1b27c27 commit e114848
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 240 deletions.
14 changes: 7 additions & 7 deletions GPU/Common/GPUDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool GEExpressionFunctions::parseReference(char *str, uint32_t &referenceIndex)
// For now, let's just support the register bits directly.
GECmdInfo info;
if (GECmdInfoByName(str, info)) {
referenceIndex = info.reg;
referenceIndex = info.cmd;
return true;
}

Expand Down Expand Up @@ -599,8 +599,8 @@ bool GEExpressionFunctions::parseFieldReference(const char *ref, const char *fie
}

for (const auto &entry : fieldNames) {
if (entry.fmt == info.fmt && strcasecmp(field, entry.name) == 0) {
referenceIndex = (info.reg << 12) | (uint32_t)entry.field;
if (entry.fmt == info.cmdFmt && strcasecmp(field, entry.name) == 0) {
referenceIndex = (info.cmd << 12) | (uint32_t)entry.field;
return true;
}
}
Expand All @@ -624,7 +624,7 @@ bool GEExpressionFunctions::parseSymbol(char *str, uint32_t &symbolValue) {
uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) {
GPUgstate state = gpu_->GetGState();
if (referenceIndex < 0x100) {
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).fmt;
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).cmdFmt;
uint32_t value = state.cmdmem[referenceIndex];
if (fmt == GECmdFormat::FLOAT)
return value << 8;
Expand All @@ -633,7 +633,7 @@ uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) {

if (referenceIndex >= (uint32_t)GEReferenceIndex::FIELD_START && referenceIndex <= (uint32_t)GEReferenceIndex::FIELD_END) {
uint32_t value = state.cmdmem[referenceIndex >> 12] & 0x00FFFFFF;
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).fmt;
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).cmdFmt;
return getFieldValue(fmt, GECmdField(referenceIndex & 0xFF), value);
}

Expand Down Expand Up @@ -898,14 +898,14 @@ uint32_t GEExpressionFunctions::getFieldValue(GECmdFormat fmt, GECmdField field,

ExpressionType GEExpressionFunctions::getReferenceType(uint32_t referenceIndex) {
if (referenceIndex < 0x100) {
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).fmt;
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).cmdFmt;
if (fmt == GECmdFormat::FLOAT)
return EXPR_TYPE_FLOAT;
return EXPR_TYPE_UINT;
}

if (referenceIndex >= (uint32_t)GEReferenceIndex::FIELD_START && referenceIndex <= (uint32_t)GEReferenceIndex::FIELD_END) {
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).fmt;
GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).cmdFmt;
return getFieldType(fmt, GECmdField(referenceIndex & 0xFF));
}

Expand Down
1 change: 1 addition & 0 deletions GPU/Debugger/Breakpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <string>
#include "Common/CommonTypes.h"

namespace GPUBreakpoints {
Expand Down
28 changes: 25 additions & 3 deletions GPU/Debugger/GECommandTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "Common/Common.h"
#include "Common/Log.h"
#include "GPU/Debugger/GECommandTable.h"
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/ge_constants.h"
#include "StringUtils.h"

struct GECmdAlias {
GECommand reg;
Expand Down Expand Up @@ -393,15 +395,15 @@ static constexpr GECmdAlias geCmdAliases[] = {

bool GECmdInfoByName(const char *name, GECmdInfo &result) {
for (const GECmdInfo &info : geCmdInfo) {
if (strcasecmp(info.name, name) == 0) {
if (equalsNoCase(info.name, name)) {
result = info;
return true;
}
}

for (const GECmdAlias &entry : geCmdAliases) {
for (const char *alias : entry.aliases) {
if (alias && strcasecmp(alias, name) == 0) {
if (alias && equalsNoCase(alias, name)) {
result = GECmdInfoByCmd(entry.reg);
return true;
}
Expand All @@ -411,7 +413,27 @@ bool GECmdInfoByName(const char *name, GECmdInfo &result) {
return false;
}

GECmdInfo GECmdInfoByCmd(GECommand reg) {
const GECmdInfo &GECmdInfoByCmd(GECommand reg) {
_assert_msg_((reg & 0xFF) == reg, "Invalid reg");
return geCmdInfo[reg & 0xFF];
}

bool ToggleBreakpoint(const GECmdInfo &info) {
using namespace GPUBreakpoints;
if (IsCmdBreakpoint(info.cmd)) {
RemoveCmdBreakpoint(info.cmd);
if (info.otherCmd)
RemoveCmdBreakpoint(info.otherCmd);
if (info.otherCmd2)
RemoveCmdBreakpoint(info.otherCmd2);
return false;
}

AddCmdBreakpoint(info.cmd);
if (info.otherCmd)
AddCmdBreakpoint(info.otherCmd);
if (info.otherCmd2)
AddCmdBreakpoint(info.otherCmd2);
return true;
}

17 changes: 10 additions & 7 deletions GPU/Debugger/GECommandTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#pragma once

#include <cstdint>
#include <string_view>

#include "GPU/ge_constants.h"

enum class GECmdFormat {
Expand Down Expand Up @@ -116,17 +118,18 @@ enum CmdFormatType {
CMD_FMT_INTEGER = CMD_FMT_HEX,
};


struct GECmdInfo {
GECommand reg;
const char *name; // scripting / expression name
GECmdFormat fmt;
const char *uiName; // friendly name
CmdFormatType fmtType;
GECommand cmd;
std::string_view name; // scripting / expression name
GECmdFormat cmdFmt;
std::string_view uiName; // friendly name
CmdFormatType fmt;
uint8_t enableCmd;
uint8_t otherCmd;
uint8_t otherCmd2;
};

bool GECmdInfoByName(const char *name, GECmdInfo &info);
GECmdInfo GECmdInfoByCmd(GECommand reg);
const GECmdInfo &GECmdInfoByCmd(GECommand reg);

bool ToggleBreakpoint(const GECmdInfo &info);
Loading

0 comments on commit e114848

Please sign in to comment.