Skip to content

Commit

Permalink
Show vertex decoders separately in profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 19, 2023
1 parent 1fa7c50 commit f86189c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
30 changes: 30 additions & 0 deletions GPU/Common/DrawEngineCommon.cpp
Expand Up @@ -1036,3 +1036,33 @@ void TessellationDataTransfer::CopyControlPoints(float *pos, float *tex, float *
}
}
}

bool DrawEngineCommon::DescribeCodePtr(const u8 *ptr, std::string &name) const {
if (!decJitCache_ || !decJitCache_->IsInSpace(ptr)) {
return false;
}

// Loop through all the decoders and see if we have a match.
VertexDecoder *found = nullptr;
u32 foundKey;

decoderMap_.Iterate([&](u32 key, VertexDecoder *value) {
if (!found) {
if (value->IsInSpace(ptr)) {
foundKey = key;
found = value;
}
}
});

if (found) {
char temp[256];
found->ToString(temp, false);
name = temp;
snprintf(temp, sizeof(temp), "_%08X", foundKey);
name += temp;
return true;
} else {
return false;
}
}
6 changes: 1 addition & 5 deletions GPU/Common/DrawEngineCommon.h
Expand Up @@ -138,11 +138,7 @@ class DrawEngineCommon {
everUsedExactEqualDepth_ = v;
}

bool IsCodePtrVertexDecoder(const u8 *ptr) const {
if (decJitCache_)
return decJitCache_->IsInSpace(ptr);
return false;
}
bool DescribeCodePtr(const u8 *ptr, std::string &name) const;
int GetNumDrawCalls() const {
return numDrawVerts_;
}
Expand Down
22 changes: 16 additions & 6 deletions GPU/Common/VertexDecoderCommon.cpp
Expand Up @@ -1276,7 +1276,7 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options,

if (reportNoPos) {
char temp[256]{};
ToString(temp);
ToString(temp, true);
ERROR_LOG_REPORT(G3D, "Vertices without position found: (%08x) %s", fmt_, temp);
}

Expand Down Expand Up @@ -1402,7 +1402,7 @@ void VertexDecoder::CompareToJit(const u8 *startPtr, u8 *decodedptr, int count,
jittedReader.Goto(i);
if (!DecodedVertsAreSimilar(controlReader, jittedReader)) {
char name[512]{};
ToString(name);
ToString(name, true);
ERROR_LOG(G3D, "Encountered vertexjit mismatch at %d/%d for %s", i, count, name);
if (morphcount > 1) {
printf("Morph:\n");
Expand Down Expand Up @@ -1456,8 +1456,9 @@ static const char *idxnames[4] = { "-", "u8", "u16", "?" };
static const char *weightnames[4] = { "-", "u8", "u16", "f" };
static const char *colnames[8] = { "", "?", "?", "?", "565", "5551", "4444", "8888" };

int VertexDecoder::ToString(char *output) const {
char * start = output;
int VertexDecoder::ToString(char *output, bool spaces) const {
char *start = output;

output += sprintf(output, "P: %s ", posnames[pos]);
if (nrm)
output += sprintf(output, "N: %s ", nrmnames[nrm]);
Expand All @@ -1474,15 +1475,24 @@ int VertexDecoder::ToString(char *output) const {
if (throughmode)
output += sprintf(output, " (through)");

output += sprintf(output, " (size: %i)", VertexSize());
output += sprintf(output, " (%ib)", VertexSize());

if (!spaces) {
size_t len = strlen(start);
for (int i = 0; i < len; i++) {
if (start[i] == ' ')
start[i] = '_';
}
}

return output - start;
}

std::string VertexDecoder::GetString(DebugShaderStringType stringType) {
char buffer[256];
switch (stringType) {
case SHADER_STRING_SHORT_DESC:
ToString(buffer);
ToString(buffer, true);
return std::string(buffer);
case SHADER_STRING_SOURCE_CODE:
{
Expand Down
7 changes: 6 additions & 1 deletion GPU/Common/VertexDecoderCommon.h
Expand Up @@ -431,7 +431,11 @@ class VertexDecoder {
// output must be big for safety.
// Returns number of chars written.
// Ugly for speed.
int ToString(char *output) const;
int ToString(char *output, bool spaces) const;

bool IsInSpace(const uint8_t *ptr) const {
return ptr >= (const uint8_t *)jitted_ && ptr < ((const uint8_t *)jitted_ + jittedSize_);
}

// Mutable decoder state
mutable u8 *decoded_ = nullptr;
Expand Down Expand Up @@ -507,6 +511,7 @@ class VertexDecoderJitCache : public VERTEXDECODER_JIT_BACKEND {

// Returns a pointer to the code to run.
JittedVertexDecoder Compile(const VertexDecoder &dec, int32_t *jittedSize);
bool DescribeCodePtr(const u8 *ptr, std::string &name) const;
void Clear();

void Jit_WeightsU8();
Expand Down
8 changes: 3 additions & 5 deletions GPU/GPUCommon.cpp
Expand Up @@ -1938,11 +1938,9 @@ bool GPUCommon::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex>
}

bool GPUCommon::DescribeCodePtr(const u8 *ptr, std::string &name) {
if (drawEngineCommon_->IsCodePtrVertexDecoder(ptr)) {
name = "VertexDecoderJit";
return true;
}
return false;
// The only part of GPU emulation (other than software) that jits is the vertex decoder, currently,
// which is owned by the drawengine.
return drawEngineCommon_->DescribeCodePtr(ptr, name);
}

void GPUCommon::UpdateUVScaleOffset() {
Expand Down

0 comments on commit f86189c

Please sign in to comment.