зеркало из https://github.com/stride3d/xkslang.git
Performance: Simple upgrade/cleanup of stl c++11 containers (10% perf. increase).
This commit is contained in:
Родитель
f4673162b7
Коммит
2f273369e4
|
@ -117,11 +117,11 @@ protected:
|
|||
const glslang::TIntermediate* glslangIntermediate;
|
||||
spv::Id stdBuiltins;
|
||||
|
||||
std::map<int, spv::Id> symbolValues;
|
||||
std::set<int> constReadOnlyParameters; // set of formal function parameters that have glslang qualifier constReadOnly, so we know they are not local function "const" that are write-once
|
||||
std::map<std::string, spv::Function*> functionMap;
|
||||
std::map<const glslang::TTypeList*, spv::Id> structMap;
|
||||
std::map<const glslang::TTypeList*, std::vector<int> > memberRemapper; // for mapping glslang block indices to spv indices (e.g., due to hidden members)
|
||||
std::unordered_map<int, spv::Id> symbolValues;
|
||||
std::unordered_set<int> constReadOnlyParameters; // set of formal function parameters that have glslang qualifier constReadOnly, so we know they are not local function "const" that are write-once
|
||||
std::unordered_map<std::string, spv::Function*> functionMap;
|
||||
std::unordered_map<const glslang::TTypeList*, spv::Id> structMap;
|
||||
std::unordered_map<const glslang::TTypeList*, std::vector<int> > memberRemapper; // for mapping glslang block indices to spv indices (e.g., due to hidden members)
|
||||
std::stack<bool> breakForLoop; // false means break for switch
|
||||
std::stack<glslang::TIntermTyped*> loopTerminal; // code from the last part of a for loop: for(...; ...; terminal), needed for e.g., continue };
|
||||
};
|
||||
|
@ -361,8 +361,8 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(const glslang::TIntermediate* gls
|
|||
builder.addEntryPoint(executionModel, shaderEntry);
|
||||
|
||||
// Add the source extensions
|
||||
const std::set<std::string>& sourceExtensions = glslangIntermediate->getRequestedExtensions();
|
||||
for (std::set<std::string>::const_iterator it = sourceExtensions.begin(); it != sourceExtensions.end(); ++it)
|
||||
const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions();
|
||||
for (auto it = sourceExtensions.begin(); it != sourceExtensions.end(); ++it)
|
||||
builder.addSourceExtension(it->c_str());
|
||||
|
||||
// Add the top-level modes for this shader.
|
||||
|
@ -2385,8 +2385,7 @@ spv::Id TGlslangToSpvTraverser::createNoArgOperation(glslang::TOperator op)
|
|||
|
||||
spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol)
|
||||
{
|
||||
std::map<int, spv::Id>::iterator iter;
|
||||
iter = symbolValues.find(symbol->getId());
|
||||
auto iter = symbolValues.find(symbol->getId());
|
||||
spv::Id id;
|
||||
if (symbolValues.end() != iter) {
|
||||
id = iter->second;
|
||||
|
|
|
@ -59,8 +59,10 @@
|
|||
#endif
|
||||
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
@ -82,10 +84,6 @@
|
|||
void operator delete[](void*) { } \
|
||||
void operator delete[](void *, void *) { }
|
||||
|
||||
#define TBaseMap std::map
|
||||
#define TBaseList std::list
|
||||
#define TBaseSet std::set
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
|
@ -93,10 +91,15 @@ namespace glslang {
|
|||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
|
||||
struct TStringHash {
|
||||
size_t operator()(const TString& string) const { return std::hash<TString>()(string); }
|
||||
};
|
||||
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||
return new(memory) TString(s);
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||
return new(memory) TString(s);
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T)
|
||||
|
@ -123,28 +126,32 @@ public:
|
|||
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
|
||||
};
|
||||
|
||||
template <class T> class TList : public TBaseList <T, pool_allocator<T> > {
|
||||
template <class T> class TList : public std::list<T, pool_allocator<T> > {
|
||||
public:
|
||||
typedef typename TBaseList<T, pool_allocator<T> >::size_type size_type;
|
||||
TList() : TBaseList<T, pool_allocator<T> >() {}
|
||||
TList(const pool_allocator<T>& a) : TBaseList<T, pool_allocator<T> >(a) {}
|
||||
TList(size_type i): TBaseList<T, pool_allocator<T> >(i) {}
|
||||
typedef typename std::list<T, pool_allocator<T> >::size_type size_type;
|
||||
TList() : std::list<T, pool_allocator<T> >() {}
|
||||
TList(const pool_allocator<T>& a) : std::list<T, pool_allocator<T> >(a) {}
|
||||
TList(size_type i): std::list<T, pool_allocator<T> >(i) {}
|
||||
};
|
||||
|
||||
// This is called TStlSet, because TSet is taken by an existing compiler class.
|
||||
template <class T, class CMP> class TStlSet : public std::set<T, CMP, pool_allocator<T> > {
|
||||
// No pool allocator versions of constructors in std::set.
|
||||
};
|
||||
|
||||
|
||||
template <class K, class D, class CMP = std::less<K> >
|
||||
class TMap : public TBaseMap<K, D, CMP, pool_allocator<std::pair<K, D> > > {
|
||||
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<K, D> > > {
|
||||
public:
|
||||
typedef pool_allocator<std::pair <K, D> > tAllocator;
|
||||
|
||||
TMap() : TBaseMap<K, D, CMP, tAllocator >() {}
|
||||
TMap() : std::map<K, D, CMP, tAllocator >() {}
|
||||
// use correct two-stage name lookup supported in gcc 3.4 and above
|
||||
TMap(const tAllocator& a) : TBaseMap<K, D, CMP, tAllocator>(TBaseMap<K, D, CMP, tAllocator >::key_compare(), a) {}
|
||||
TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(TBaseMap<K, D, CMP, tAllocator >::key_compare(), a) {}
|
||||
};
|
||||
|
||||
template <class K, class D, class HASH = std::hash<K>, class PRED = std::equal_to<K> >
|
||||
class TUnorderedMap : public std::unordered_map<K, D, HASH, PRED, pool_allocator<std::pair<K, D> > > {
|
||||
public:
|
||||
typedef pool_allocator<std::pair <K, D> > tAllocator;
|
||||
|
||||
TUnorderedMap() : std::unordered_map<K, D, HASH, PRED, tAllocator >() {}
|
||||
// use correct two-stage name lookup supported in gcc 3.4 and above
|
||||
TUnorderedMap(const tAllocator& a) : std::unordered_map<K, D, HASH, PRED, tAllocator>(TBaseMap<K, D, HASH, PRED, tAllocator >::key_compare(), a) {}
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -184,7 +191,6 @@ struct TSourceLoc {
|
|||
};
|
||||
|
||||
typedef TMap<TString, TString> TPragmaTable;
|
||||
typedef TMap<TString, TString>::tAllocator TPragmaTableAllocator;
|
||||
|
||||
const int GlslangMaxTokenLength = 1024;
|
||||
|
||||
|
|
|
@ -849,9 +849,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
typedef std::map<TTypeList*, TTypeList*> TStructureMap;
|
||||
typedef std::map<TTypeList*, TTypeList*>::const_iterator TStructureMapIterator;
|
||||
|
||||
//
|
||||
// Base class for things that have a type.
|
||||
//
|
||||
|
@ -957,7 +954,6 @@ public:
|
|||
|
||||
if (copyOf.structure) {
|
||||
structure = new TTypeList;
|
||||
TStructureMapIterator iter;
|
||||
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
|
||||
TTypeLoc typeLoc;
|
||||
typeLoc.loc = (*copyOf.structure)[i].loc;
|
||||
|
|
|
@ -48,10 +48,10 @@
|
|||
namespace glslang {
|
||||
|
||||
struct TPragma {
|
||||
TPragma(bool o, bool d) : optimize(o), debug(d) { }
|
||||
bool optimize;
|
||||
bool debug;
|
||||
TPragmaTable pragmaTable;
|
||||
TPragma(bool o, bool d) : optimize(o), debug(d) { }
|
||||
bool optimize;
|
||||
bool debug;
|
||||
TPragmaTable pragmaTable;
|
||||
};
|
||||
|
||||
class TScanContext;
|
||||
|
@ -306,7 +306,7 @@ protected:
|
|||
TInputScanner* currentScanner;
|
||||
int numErrors; // number of compile-time errors encountered
|
||||
bool parsingBuiltins; // true if parsing built-in symbols/functions
|
||||
TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
std::unordered_map<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex()
|
||||
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
|
||||
bool afterEOF;
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
//
|
||||
|
||||
#include <string.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "../Include/Types.h"
|
||||
#include "SymbolTable.h"
|
||||
|
@ -293,8 +295,8 @@ namespace {
|
|||
|
||||
// A single global usable by all threads, by all versions, by all languages.
|
||||
// After a single process-level initialization, this is read only and thread safe
|
||||
std::map<std::string, int>* KeywordMap = 0;
|
||||
std::set<std::string>* ReservedSet = 0;
|
||||
std::unordered_map<std::string, int>* KeywordMap = 0;
|
||||
std::unordered_set<std::string>* ReservedSet = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -307,7 +309,7 @@ void TScanContext::fillInKeywordMap()
|
|||
// but, the only risk is if two threads called simultaneously
|
||||
return;
|
||||
}
|
||||
KeywordMap = new std::map<std::string, int>;
|
||||
KeywordMap = new std::unordered_map<std::string, int>;
|
||||
|
||||
(*KeywordMap)["const"] = CONST;
|
||||
(*KeywordMap)["uniform"] = UNIFORM;
|
||||
|
@ -476,7 +478,7 @@ void TScanContext::fillInKeywordMap()
|
|||
(*KeywordMap)["resource"] = RESOURCE;
|
||||
(*KeywordMap)["superp"] = SUPERP;
|
||||
|
||||
ReservedSet = new std::set<std::string>;
|
||||
ReservedSet = new std::unordered_set<std::string>;
|
||||
|
||||
ReservedSet->insert("common");
|
||||
ReservedSet->insert("partition");
|
||||
|
@ -610,7 +612,7 @@ int TScanContext::tokenizeIdentifier()
|
|||
if (ReservedSet->find(tokenText) != ReservedSet->end())
|
||||
return reservedWord();
|
||||
|
||||
std::map<std::string, int>::const_iterator it = KeywordMap->find(tokenText);
|
||||
auto it = KeywordMap->find(tokenText);
|
||||
if (it == KeywordMap->end()) {
|
||||
// Should have an identifier of some sort
|
||||
return identifierOrType();
|
||||
|
|
|
@ -441,7 +441,7 @@ void TParseContext::requireExtensions(TSourceLoc loc, int numExtensions, const c
|
|||
|
||||
TExtensionBehavior TParseContext::getExtensionBehavior(const char* extension)
|
||||
{
|
||||
TMap<TString, TExtensionBehavior>::iterator iter = extensionBehavior.find(TString(extension));
|
||||
auto iter = extensionBehavior.find(TString(extension));
|
||||
if (iter == extensionBehavior.end())
|
||||
return EBhMissing;
|
||||
else
|
||||
|
@ -527,19 +527,18 @@ void TParseContext::updateExtensionBehavior(int line, const char* extension, con
|
|||
void TParseContext::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
|
||||
{
|
||||
// Update the current behavior
|
||||
TMap<TString, TExtensionBehavior>::iterator iter;
|
||||
if (strcmp(extension, "all") == 0) {
|
||||
// special case for the 'all' extension; apply it to every extension present
|
||||
if (behavior == EBhRequire || behavior == EBhEnable) {
|
||||
error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
|
||||
return;
|
||||
} else {
|
||||
for (iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
|
||||
for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
|
||||
iter->second = behavior;
|
||||
}
|
||||
} else {
|
||||
// Do the update for this single extension
|
||||
iter = extensionBehavior.find(TString(extension));
|
||||
auto iter = extensionBehavior.find(TString(extension));
|
||||
if (iter == extensionBehavior.end()) {
|
||||
switch (behavior) {
|
||||
case EBhRequire:
|
||||
|
|
|
@ -649,7 +649,7 @@ void TIntermediate::output(TInfoSink& infoSink, bool tree)
|
|||
{
|
||||
infoSink.debug << "Shader version: " << version << "\n";
|
||||
if (requestedExtensions.size() > 0) {
|
||||
for (std::set<std::string>::const_iterator extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
|
||||
for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
|
||||
infoSink.debug << "Requested " << *extIt << "\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace glslang {
|
|||
//
|
||||
int TPpContext::LookUpAddString(const char* s)
|
||||
{
|
||||
TAtomMap::const_iterator it = atomMap.find(s);
|
||||
auto it = atomMap.find(s);
|
||||
if (it == atomMap.end())
|
||||
return AddAtomFixed(s, nextAtom++);
|
||||
else
|
||||
|
@ -161,7 +161,7 @@ const char* TPpContext::GetAtomString(int atom)
|
|||
//
|
||||
int TPpContext::AddAtomFixed(const char* s, int atom)
|
||||
{
|
||||
TAtomMap::const_iterator it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||
if (stringMap.size() < (size_t)atom + 1)
|
||||
stringMap.resize(atom + 100, 0);
|
||||
stringMap[atom] = &it->first;
|
||||
|
|
|
@ -78,6 +78,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef PPCONTEXT_H
|
||||
#define PPCONTEXT_H
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../ParseHelper.h"
|
||||
|
||||
#pragma warning(disable : 4127)
|
||||
|
@ -190,7 +192,7 @@ public:
|
|||
};
|
||||
|
||||
MemoryPool *pool;
|
||||
typedef std::map<int, Symbol*> TSymbolMap;
|
||||
typedef TUnorderedMap<int, Symbol*> TSymbolMap;
|
||||
TSymbolMap symbols; // this has light use... just defined macros
|
||||
|
||||
protected:
|
||||
|
@ -459,7 +461,7 @@ protected:
|
|||
//
|
||||
// From PpAtom.cpp
|
||||
//
|
||||
typedef std::map<const TString, int> TAtomMap;
|
||||
typedef TUnorderedMap<const TString, int, TStringHash> TAtomMap;
|
||||
typedef TVector<const TString*> TStringMap;
|
||||
TAtomMap atomMap;
|
||||
TStringMap stringMap;
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
protected:
|
||||
friend class glslang::TLiveTraverser;
|
||||
|
||||
typedef std::map<TString, int> TNameToIndex;
|
||||
typedef std::unordered_map<TString, int> TNameToIndex;
|
||||
typedef std::vector<TObjectReflection> TMapIndexToReflection;
|
||||
|
||||
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
|
||||
|
|
Загрузка…
Ссылка в новой задаче