Skip to content

Commit

Permalink
Vertex Format Reset Optimization (#1372)
Browse files Browse the repository at this point in the history
Clear the current vertex format on begin instead of calling the default constructor to avoid reallocating its flags vector and speed up vertex format declaring.
  • Loading branch information
RobertBColton committed Aug 29, 2018
1 parent 92ccfca commit 8876f61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ENIGMAsystem/SHELL/Graphics_Systems/General/GSvertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::unordered_map<size_t, int> vertexFormatCache;

// current vertex format being specified
// NOTE: this is not reset until the next vertex_format_begin
// NOTE: this uses the stack until vertex_format_end to speed up creation
// NOTE: this has static storage duration to avoid reallocation overhead (e.g, new is slow)
enigma::VertexFormat currentVertexFormat;

#define RESOURCE_EXISTS(id, container) return (id >= 0 && (unsigned)id < enigma::container.size() && enigma::container[id] != nullptr);
Expand All @@ -59,7 +59,10 @@ vector<IndexBuffer*> indexBuffers;
namespace enigma_user {

void vertex_format_begin() {
currentVertexFormat = enigma::VertexFormat();
// resetting the current vertex format this way is faster
// than simply calling the default constructor because we
// avoid reallocating the flags vector this way
currentVertexFormat.Clear();
}

unsigned vertex_format_get_hash() {
Expand Down
5 changes: 5 additions & 0 deletions ENIGMAsystem/SHELL/Graphics_Systems/General/GSvertex_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ struct VertexFormat {

VertexFormat(): stride(0), stride_size(0), hash(0) {}

void Clear() {
hash = stride = stride_size = 0;
flags.clear();
}

void AddAttribute(int type, int attribute) {
using namespace enigma_user;

Expand Down

0 comments on commit 8876f61

Please sign in to comment.