Merge pull request #5176 from lioncash/retval

VertexLoader: Return debug strings by value
This commit is contained in:
Matthew Parlane 2017-03-28 15:38:32 +13:00 committed by GitHub
commit 94dd435336
6 changed files with 48 additions and 42 deletions

View File

@ -68,8 +68,7 @@ std::string Statistics::ToString()
str += StringFromFormat("Uniform streamed: %i kB\n", stats.thisFrame.bytesUniformStreamed / 1024); str += StringFromFormat("Uniform streamed: %i kB\n", stats.thisFrame.bytesUniformStreamed / 1024);
str += StringFromFormat("Vertex Loaders: %i\n", stats.numVertexLoaders); str += StringFromFormat("Vertex Loaders: %i\n", stats.numVertexLoaders);
std::string vertex_list; std::string vertex_list = VertexLoaderManager::VertexLoadersToString();
VertexLoaderManager::AppendListToString(&vertex_list);
// TODO : at some point text1 just becomes too huge and overflows, we can't even read the added // TODO : at some point text1 just becomes too huge and overflows, we can't even read the added
// stuff // stuff

View File

@ -2,6 +2,9 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "VideoCommon/VertexLoaderBase.h"
#include <array>
#include <cinttypes> #include <cinttypes>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
@ -15,7 +18,6 @@
#include "VideoCommon/DataReader.h" #include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoader.h"
#include "VideoCommon/VertexLoaderBase.h"
#ifdef _M_X86_64 #ifdef _M_X86_64
#include "VideoCommon/VertexLoaderX64.h" #include "VideoCommon/VertexLoaderX64.h"
@ -70,55 +72,56 @@ void VertexLoaderBase::SetVAT(const VAT& vat)
m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac; m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac;
}; };
void VertexLoaderBase::AppendToString(std::string* dest) const std::string VertexLoaderBase::ToString() const
{ {
dest->reserve(250); std::string dest;
dest.reserve(250);
dest->append(GetName()); dest += GetName();
dest->append(": "); dest += ": ";
static const char* posMode[4] = { static constexpr std::array<const char*, 4> pos_mode{{
"Inv", "Dir", "I8", "I16", "Inv", "Dir", "I8", "I16",
}; }};
static const char* posFormats[8] = { static constexpr std::array<const char*, 8> pos_formats{{
"u8", "s8", "u16", "s16", "flt", "Inv", "Inv", "Inv", "u8", "s8", "u16", "s16", "flt", "Inv", "Inv", "Inv",
}; }};
static const char* colorFormat[8] = { static constexpr std::array<const char*, 8> color_format{{
"565", "888", "888x", "4444", "6666", "8888", "Inv", "Inv", "565", "888", "888x", "4444", "6666", "8888", "Inv", "Inv",
}; }};
dest->append(StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx, dest += StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx,
m_VtxAttr.PosElements ? 3 : 2, posMode[m_VtxDesc.Position], m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position],
posFormats[m_VtxAttr.PosFormat])); pos_formats[m_VtxAttr.PosFormat]);
if (m_VtxDesc.Normal) if (m_VtxDesc.Normal)
{ {
dest->append(StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, dest += StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, pos_mode[m_VtxDesc.Normal],
posMode[m_VtxDesc.Normal], posFormats[m_VtxAttr.NormalFormat])); pos_formats[m_VtxAttr.NormalFormat]);
} }
u64 color_mode[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1}; const std::array<u64, 2> color_mode{{m_VtxDesc.Color0, m_VtxDesc.Color1}};
for (int i = 0; i < 2; i++) for (size_t i = 0; i < color_mode.size(); i++)
{ {
if (color_mode[i]) if (color_mode[i])
{ {
dest->append(StringFromFormat("C%i: %i %s-%s ", i, m_VtxAttr.color[i].Elements, dest += StringFromFormat("C%zu: %i %s-%s ", i, m_VtxAttr.color[i].Elements,
posMode[color_mode[i]], colorFormat[m_VtxAttr.color[i].Comp])); pos_mode[color_mode[i]], color_format[m_VtxAttr.color[i].Comp]);
} }
} }
u64 tex_mode[8] = {m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, const std::array<u64, 8> tex_mode{{m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord,
m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord,
m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}; m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}};
for (int i = 0; i < 8; i++) for (size_t i = 0; i < tex_mode.size(); i++)
{ {
if (tex_mode[i]) if (tex_mode[i])
{ {
dest->append(StringFromFormat("T%i: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements, dest += StringFromFormat("T%zu: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements,
posMode[tex_mode[i]], pos_mode[tex_mode[i]], pos_formats[m_VtxAttr.texCoord[i].Format]);
posFormats[m_VtxAttr.texCoord[i].Format]));
} }
} }
dest->append(StringFromFormat(" - %i v", m_numLoadedVertices)); dest += StringFromFormat(" - %i v", m_numLoadedVertices);
return dest;
} }
// a hacky implementation to compare two vertex loaders // a hacky implementation to compare two vertex loaders

View File

@ -67,7 +67,7 @@ public:
virtual bool IsInitialized() = 0; virtual bool IsInitialized() = 0;
// For debugging / profiling // For debugging / profiling
void AppendToString(std::string* dest) const; std::string ToString() const;
virtual std::string GetName() const = 0; virtual std::string GetName() const = 0;

View File

@ -98,7 +98,7 @@ struct entry
}; };
} }
void AppendListToString(std::string* dest) std::string VertexLoadersToString()
{ {
std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock); std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
std::vector<entry> entries; std::vector<entry> entries;
@ -106,19 +106,24 @@ void AppendListToString(std::string* dest)
size_t total_size = 0; size_t total_size = 0;
for (const auto& map_entry : s_vertex_loader_map) for (const auto& map_entry : s_vertex_loader_map)
{ {
entry e; entry e = {map_entry.second->ToString(),
map_entry.second->AppendToString(&e.text); static_cast<u64>(map_entry.second->m_numLoadedVertices)};
e.num_verts = map_entry.second->m_numLoadedVertices;
entries.push_back(e);
total_size += e.text.size() + 1; total_size += e.text.size() + 1;
entries.push_back(std::move(e));
} }
sort(entries.begin(), entries.end()); sort(entries.begin(), entries.end());
dest->reserve(dest->size() + total_size);
std::string dest;
dest.reserve(total_size);
for (const entry& entry : entries) for (const entry& entry : entries)
{ {
*dest += entry.text; dest += entry.text;
*dest += '\n'; dest += '\n';
} }
return dest;
} }
void MarkAllDirty() void MarkAllDirty()

View File

@ -30,7 +30,7 @@ NativeVertexFormatMap* GetNativeVertexFormatMap();
int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool is_preprocess); int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool is_preprocess);
// For debugging // For debugging
void AppendListToString(std::string* dest); std::string VertexLoadersToString();
NativeVertexFormat* GetCurrentVertexFormat(); NativeVertexFormat* GetCurrentVertexFormat();

View File

@ -51,8 +51,7 @@ VertexLoaderX64::VertexLoaderX64(const TVtxDesc& vtx_desc, const VAT& vtx_att)
GenerateVertexLoader(); GenerateVertexLoader();
WriteProtect(); WriteProtect();
std::string name; const std::string name = ToString();
AppendToString(&name);
JitRegister::Register(region, GetCodePtr(), name.c_str()); JitRegister::Register(region, GetCodePtr(), name.c_str());
} }