From 8033a72f0bbea732b9a1bf5d6110bde6632f49a6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 26 Mar 2017 22:12:20 -0400 Subject: [PATCH 1/3] VertexLoaderBase: Use std::array where applicable --- Source/Core/VideoCommon/VertexLoaderBase.cpp | 44 ++++++++++---------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp index ce637401ac..d65e0d053f 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.cpp +++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp @@ -2,6 +2,9 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "VideoCommon/VertexLoaderBase.h" + +#include #include #include #include @@ -15,7 +18,6 @@ #include "VideoCommon/DataReader.h" #include "VideoCommon/VertexLoader.h" -#include "VideoCommon/VertexLoaderBase.h" #ifdef _M_X86_64 #include "VideoCommon/VertexLoaderX64.h" @@ -77,45 +79,45 @@ void VertexLoaderBase::AppendToString(std::string* dest) const dest->append(GetName()); dest->append(": "); - static const char* posMode[4] = { + static constexpr std::array pos_mode{{ "Inv", "Dir", "I8", "I16", - }; - static const char* posFormats[8] = { + }}; + static constexpr std::array pos_formats{{ "u8", "s8", "u16", "s16", "flt", "Inv", "Inv", "Inv", - }; - static const char* colorFormat[8] = { + }}; + static constexpr std::array color_format{{ "565", "888", "888x", "4444", "6666", "8888", "Inv", "Inv", - }; + }}; dest->append(StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx, - m_VtxAttr.PosElements ? 3 : 2, posMode[m_VtxDesc.Position], - posFormats[m_VtxAttr.PosFormat])); + m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position], + pos_formats[m_VtxAttr.PosFormat])); if (m_VtxDesc.Normal) { dest->append(StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, - posMode[m_VtxDesc.Normal], posFormats[m_VtxAttr.NormalFormat])); + pos_mode[m_VtxDesc.Normal], pos_formats[m_VtxAttr.NormalFormat])); } - u64 color_mode[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1}; - for (int i = 0; i < 2; i++) + const std::array color_mode{{m_VtxDesc.Color0, m_VtxDesc.Color1}}; + for (size_t i = 0; i < color_mode.size(); i++) { if (color_mode[i]) { - dest->append(StringFromFormat("C%i: %i %s-%s ", i, m_VtxAttr.color[i].Elements, - posMode[color_mode[i]], colorFormat[m_VtxAttr.color[i].Comp])); + dest->append(StringFromFormat("C%zu: %i %s-%s ", i, m_VtxAttr.color[i].Elements, + 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, - m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, - m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}; - for (int i = 0; i < 8; i++) + const std::array tex_mode{{m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, + m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, + m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}}; + for (size_t i = 0; i < tex_mode.size(); i++) { if (tex_mode[i]) { - dest->append(StringFromFormat("T%i: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements, - posMode[tex_mode[i]], - posFormats[m_VtxAttr.texCoord[i].Format])); + dest->append(StringFromFormat("T%zu: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements, + pos_mode[tex_mode[i]], + pos_formats[m_VtxAttr.texCoord[i].Format])); } } dest->append(StringFromFormat(" - %i v", m_numLoadedVertices)); From 9859533ab461c6d509337d8b9013a7ba62dd78ae Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 26 Mar 2017 22:17:37 -0400 Subject: [PATCH 2/3] VertexLoaderBase: Return debug strings by value An out parameter for this sort of thing is a C++03 hold-over. This also renames AppendToString to ToString. --- Source/Core/VideoCommon/VertexLoaderBase.cpp | 31 ++++++++++--------- Source/Core/VideoCommon/VertexLoaderBase.h | 2 +- .../Core/VideoCommon/VertexLoaderManager.cpp | 8 ++--- Source/Core/VideoCommon/VertexLoaderX64.cpp | 3 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp index d65e0d053f..21a149c169 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.cpp +++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp @@ -72,12 +72,13 @@ void VertexLoaderBase::SetVAT(const VAT& vat) 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->append(": "); + dest += GetName(); + dest += ": "; static constexpr std::array pos_mode{{ "Inv", "Dir", "I8", "I16", @@ -89,14 +90,14 @@ void VertexLoaderBase::AppendToString(std::string* dest) const "565", "888", "888x", "4444", "6666", "8888", "Inv", "Inv", }}; - dest->append(StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx, - m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position], - pos_formats[m_VtxAttr.PosFormat])); + dest += StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx, + m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position], + pos_formats[m_VtxAttr.PosFormat]); if (m_VtxDesc.Normal) { - dest->append(StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, - pos_mode[m_VtxDesc.Normal], pos_formats[m_VtxAttr.NormalFormat])); + dest += StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, pos_mode[m_VtxDesc.Normal], + pos_formats[m_VtxAttr.NormalFormat]); } const std::array color_mode{{m_VtxDesc.Color0, m_VtxDesc.Color1}}; @@ -104,8 +105,8 @@ void VertexLoaderBase::AppendToString(std::string* dest) const { if (color_mode[i]) { - dest->append(StringFromFormat("C%zu: %i %s-%s ", i, m_VtxAttr.color[i].Elements, - pos_mode[color_mode[i]], color_format[m_VtxAttr.color[i].Comp])); + dest += StringFromFormat("C%zu: %i %s-%s ", i, m_VtxAttr.color[i].Elements, + pos_mode[color_mode[i]], color_format[m_VtxAttr.color[i].Comp]); } } const std::array tex_mode{{m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, @@ -115,12 +116,12 @@ void VertexLoaderBase::AppendToString(std::string* dest) const { if (tex_mode[i]) { - dest->append(StringFromFormat("T%zu: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements, - pos_mode[tex_mode[i]], - pos_formats[m_VtxAttr.texCoord[i].Format])); + dest += StringFromFormat("T%zu: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements, + pos_mode[tex_mode[i]], pos_formats[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 diff --git a/Source/Core/VideoCommon/VertexLoaderBase.h b/Source/Core/VideoCommon/VertexLoaderBase.h index 0c1c3c50cb..a895300466 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.h +++ b/Source/Core/VideoCommon/VertexLoaderBase.h @@ -67,7 +67,7 @@ public: virtual bool IsInitialized() = 0; // For debugging / profiling - void AppendToString(std::string* dest) const; + std::string ToString() const; virtual std::string GetName() const = 0; diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index c7a2f46bab..f0d8decb3d 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -106,11 +106,11 @@ void AppendListToString(std::string* dest) size_t total_size = 0; for (const auto& map_entry : s_vertex_loader_map) { - entry e; - map_entry.second->AppendToString(&e.text); - e.num_verts = map_entry.second->m_numLoadedVertices; - entries.push_back(e); + entry e = {map_entry.second->ToString(), + static_cast(map_entry.second->m_numLoadedVertices)}; + total_size += e.text.size() + 1; + entries.push_back(std::move(e)); } sort(entries.begin(), entries.end()); dest->reserve(dest->size() + total_size); diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index 6b3f538bf4..92edf8dd5c 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -51,8 +51,7 @@ VertexLoaderX64::VertexLoaderX64(const TVtxDesc& vtx_desc, const VAT& vtx_att) GenerateVertexLoader(); WriteProtect(); - std::string name; - AppendToString(&name); + const std::string name = ToString(); JitRegister::Register(region, GetCodePtr(), name.c_str()); } From 9ebd84e54afecee306b4bbc97fa15604def37310 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 26 Mar 2017 22:52:10 -0400 Subject: [PATCH 3/3] VertexLoaderManager: Return debug strings by value This also renames AppendListToString to VertexLoadersToString. --- Source/Core/VideoCommon/Statistics.cpp | 3 +-- Source/Core/VideoCommon/VertexLoaderManager.cpp | 13 +++++++++---- Source/Core/VideoCommon/VertexLoaderManager.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index 1497a3df30..0a4a9236b0 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -68,8 +68,7 @@ std::string Statistics::ToString() str += StringFromFormat("Uniform streamed: %i kB\n", stats.thisFrame.bytesUniformStreamed / 1024); str += StringFromFormat("Vertex Loaders: %i\n", stats.numVertexLoaders); - std::string vertex_list; - VertexLoaderManager::AppendListToString(&vertex_list); + std::string vertex_list = VertexLoaderManager::VertexLoadersToString(); // TODO : at some point text1 just becomes too huge and overflows, we can't even read the added // stuff diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index f0d8decb3d..463094e66b 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -98,7 +98,7 @@ struct entry }; } -void AppendListToString(std::string* dest) +std::string VertexLoadersToString() { std::lock_guard lk(s_vertex_loader_map_lock); std::vector entries; @@ -112,13 +112,18 @@ void AppendListToString(std::string* dest) total_size += e.text.size() + 1; entries.push_back(std::move(e)); } + sort(entries.begin(), entries.end()); - dest->reserve(dest->size() + total_size); + + std::string dest; + dest.reserve(total_size); for (const entry& entry : entries) { - *dest += entry.text; - *dest += '\n'; + dest += entry.text; + dest += '\n'; } + + return dest; } void MarkAllDirty() diff --git a/Source/Core/VideoCommon/VertexLoaderManager.h b/Source/Core/VideoCommon/VertexLoaderManager.h index bff6d4e8eb..30ceb41aec 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.h +++ b/Source/Core/VideoCommon/VertexLoaderManager.h @@ -30,7 +30,7 @@ NativeVertexFormatMap* GetNativeVertexFormatMap(); int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool is_preprocess); // For debugging -void AppendListToString(std::string* dest); +std::string VertexLoadersToString(); NativeVertexFormat* GetCurrentVertexFormat();