Clean up iomapper.h to make it suitable as a public API
Remove the dependency on LiveTraverser.h, which transitively includes localintermediate.h. As a result, some things have been moved from iomapper.h to iomapper.cpp, specifically the TVarEntry type and the constructor and destructor of TGlslIoMapper.
This commit is contained in:
parent
71c24c1e4b
commit
31584ef79d
4 changed files with 140 additions and 131 deletions
|
|
@ -37,7 +37,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "glslang/Public/ShaderLang.h"
|
#include "glslang/Public/ShaderLang.h"
|
||||||
#include "glslang/Include/ShHandle.h"
|
#include "glslang/Include/ShHandle.h"
|
||||||
|
|
||||||
|
#include "glslang/Include/BaseTypes.h"
|
||||||
#include "glslang/Include/ResourceLimits.h"
|
#include "glslang/Include/ResourceLimits.h"
|
||||||
|
#include "glslang/Include/Types.h"
|
||||||
#include "glslang/MachineIndependent/iomapper.h"
|
#include "glslang/MachineIndependent/iomapper.h"
|
||||||
#include "glslang/MachineIndependent/Versions.h"
|
#include "glslang/MachineIndependent/Versions.h"
|
||||||
#include "glslang/MachineIndependent/localintermediate.h"
|
#include "glslang/MachineIndependent/localintermediate.h"
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "gl_types.h"
|
#include "gl_types.h"
|
||||||
#include "iomapper.h"
|
#include "iomapper.h"
|
||||||
|
#include "LiveTraverser.h"
|
||||||
#include "SymbolTable.h"
|
#include "SymbolTable.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -60,6 +61,108 @@
|
||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
|
struct TVarEntryInfo {
|
||||||
|
long long id;
|
||||||
|
TIntermSymbol* symbol;
|
||||||
|
bool live;
|
||||||
|
bool upgradedToPushConstant;
|
||||||
|
int newBinding;
|
||||||
|
int newSet;
|
||||||
|
int newLocation;
|
||||||
|
int newComponent;
|
||||||
|
int newIndex;
|
||||||
|
EShLanguage stage;
|
||||||
|
|
||||||
|
void clearNewAssignments() {
|
||||||
|
upgradedToPushConstant = false;
|
||||||
|
newBinding = -1;
|
||||||
|
newSet = -1;
|
||||||
|
newLocation = -1;
|
||||||
|
newComponent = -1;
|
||||||
|
newIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TOrderById {
|
||||||
|
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TOrderByPriority {
|
||||||
|
// ordering:
|
||||||
|
// 1) has both binding and set
|
||||||
|
// 2) has binding but no set
|
||||||
|
// 3) has no binding but set
|
||||||
|
// 4) has no binding and no set
|
||||||
|
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
||||||
|
const TQualifier& lq = l.symbol->getQualifier();
|
||||||
|
const TQualifier& rq = r.symbol->getQualifier();
|
||||||
|
|
||||||
|
// simple rules:
|
||||||
|
// has binding gives 2 points
|
||||||
|
// has set gives 1 point
|
||||||
|
// who has the most points is more important.
|
||||||
|
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
||||||
|
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
||||||
|
|
||||||
|
if (lPoints == rPoints)
|
||||||
|
return l.id < r.id;
|
||||||
|
return lPoints > rPoints;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TOrderByPriorityAndLive {
|
||||||
|
// ordering:
|
||||||
|
// 1) do live variables first
|
||||||
|
// 2) has both binding and set
|
||||||
|
// 3) has binding but no set
|
||||||
|
// 4) has no binding but set
|
||||||
|
// 5) has no binding and no set
|
||||||
|
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
||||||
|
|
||||||
|
const TQualifier& lq = l.symbol->getQualifier();
|
||||||
|
const TQualifier& rq = r.symbol->getQualifier();
|
||||||
|
|
||||||
|
// simple rules:
|
||||||
|
// has binding gives 2 points
|
||||||
|
// has set gives 1 point
|
||||||
|
// who has the most points is more important.
|
||||||
|
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
||||||
|
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
||||||
|
|
||||||
|
if (l.live != r.live)
|
||||||
|
return l.live > r.live;
|
||||||
|
|
||||||
|
if (lPoints != rPoints)
|
||||||
|
return lPoints > rPoints;
|
||||||
|
|
||||||
|
return l.id < r.id;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
|
||||||
|
// when use vc++, the sort function will call :
|
||||||
|
// pair& operator=(const pair<_Other1, _Other2>& _Right)
|
||||||
|
// {
|
||||||
|
// first = _Right.first;
|
||||||
|
// second = _Right.second;
|
||||||
|
// return (*this);
|
||||||
|
// }
|
||||||
|
// that will make a const type handing on left.
|
||||||
|
// override this function can avoid a compiler error.
|
||||||
|
// In the future, if the vc++ compiler can handle such a situation,
|
||||||
|
// this part of the code will be removed.
|
||||||
|
struct TVarLivePair : std::pair<const TString, TVarEntryInfo> {
|
||||||
|
TVarLivePair(const std::pair<const TString, TVarEntryInfo>& _Right) : pair(_Right.first, _Right.second) {}
|
||||||
|
TVarLivePair& operator=(const TVarLivePair& _Right) {
|
||||||
|
const_cast<TString&>(first) = _Right.first;
|
||||||
|
second = _Right.second;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
TVarLivePair(const TVarLivePair& src) : pair(src) { }
|
||||||
|
};
|
||||||
|
typedef std::vector<TVarLivePair> TVarLiveVector;
|
||||||
|
|
||||||
|
|
||||||
class TVarGatherTraverser : public TLiveTraverser {
|
class TVarGatherTraverser : public TLiveTraverser {
|
||||||
public:
|
public:
|
||||||
TVarGatherTraverser(const TIntermediate& i, bool traverseDeadCode, TVarLiveMap& inList, TVarLiveMap& outList, TVarLiveMap& uniformList)
|
TVarGatherTraverser(const TIntermediate& i, bool traverseDeadCode, TVarLiveMap& inList, TVarLiveMap& outList, TVarLiveMap& uniformList)
|
||||||
|
|
@ -1497,6 +1600,36 @@ bool TIoMapper::addStage(EShLanguage stage, TIntermediate& intermediate, TInfoSi
|
||||||
return !hadError;
|
return !hadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TGlslIoMapper::TGlslIoMapper() {
|
||||||
|
memset(inVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
||||||
|
memset(outVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
||||||
|
memset(uniformVarMap, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
||||||
|
memset(intermediates, 0, sizeof(TIntermediate*) * (EShLangCount + 1));
|
||||||
|
profile = ENoProfile;
|
||||||
|
version = 0;
|
||||||
|
autoPushConstantMaxSize = 128;
|
||||||
|
autoPushConstantBlockPacking = ElpStd430;
|
||||||
|
}
|
||||||
|
|
||||||
|
TGlslIoMapper::~TGlslIoMapper() {
|
||||||
|
for (size_t stage = 0; stage < EShLangCount; stage++) {
|
||||||
|
if (inVarMaps[stage] != nullptr) {
|
||||||
|
delete inVarMaps[stage];
|
||||||
|
inVarMaps[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (outVarMaps[stage] != nullptr) {
|
||||||
|
delete outVarMaps[stage];
|
||||||
|
outVarMaps[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (uniformVarMap[stage] != nullptr) {
|
||||||
|
delete uniformVarMap[stage];
|
||||||
|
uniformVarMap[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (intermediates[stage] != nullptr)
|
||||||
|
intermediates[stage] = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Map I/O variables to provided offsets, and make bindings for
|
// Map I/O variables to provided offsets, and make bindings for
|
||||||
// unbound but live variables.
|
// unbound but live variables.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@
|
||||||
#define _IOMAPPER_INCLUDED
|
#define _IOMAPPER_INCLUDED
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "LiveTraverser.h"
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
//
|
//
|
||||||
|
|
@ -49,84 +48,7 @@ class TInfoSink;
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
class TIntermediate;
|
class TIntermediate;
|
||||||
struct TVarEntryInfo {
|
struct TVarEntryInfo;
|
||||||
long long id;
|
|
||||||
TIntermSymbol* symbol;
|
|
||||||
bool live;
|
|
||||||
bool upgradedToPushConstant;
|
|
||||||
int newBinding;
|
|
||||||
int newSet;
|
|
||||||
int newLocation;
|
|
||||||
int newComponent;
|
|
||||||
int newIndex;
|
|
||||||
EShLanguage stage;
|
|
||||||
|
|
||||||
void clearNewAssignments() {
|
|
||||||
upgradedToPushConstant = false;
|
|
||||||
newBinding = -1;
|
|
||||||
newSet = -1;
|
|
||||||
newLocation = -1;
|
|
||||||
newComponent = -1;
|
|
||||||
newIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TOrderById {
|
|
||||||
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TOrderByPriority {
|
|
||||||
// ordering:
|
|
||||||
// 1) has both binding and set
|
|
||||||
// 2) has binding but no set
|
|
||||||
// 3) has no binding but set
|
|
||||||
// 4) has no binding and no set
|
|
||||||
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
|
||||||
const TQualifier& lq = l.symbol->getQualifier();
|
|
||||||
const TQualifier& rq = r.symbol->getQualifier();
|
|
||||||
|
|
||||||
// simple rules:
|
|
||||||
// has binding gives 2 points
|
|
||||||
// has set gives 1 point
|
|
||||||
// who has the most points is more important.
|
|
||||||
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
|
||||||
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
|
||||||
|
|
||||||
if (lPoints == rPoints)
|
|
||||||
return l.id < r.id;
|
|
||||||
return lPoints > rPoints;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TOrderByPriorityAndLive {
|
|
||||||
// ordering:
|
|
||||||
// 1) do live variables first
|
|
||||||
// 2) has both binding and set
|
|
||||||
// 3) has binding but no set
|
|
||||||
// 4) has no binding but set
|
|
||||||
// 5) has no binding and no set
|
|
||||||
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
|
||||||
|
|
||||||
const TQualifier& lq = l.symbol->getQualifier();
|
|
||||||
const TQualifier& rq = r.symbol->getQualifier();
|
|
||||||
|
|
||||||
// simple rules:
|
|
||||||
// has binding gives 2 points
|
|
||||||
// has set gives 1 point
|
|
||||||
// who has the most points is more important.
|
|
||||||
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
|
||||||
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
|
||||||
|
|
||||||
if (l.live != r.live)
|
|
||||||
return l.live > r.live;
|
|
||||||
|
|
||||||
if (lPoints != rPoints)
|
|
||||||
return lPoints > rPoints;
|
|
||||||
|
|
||||||
return l.id < r.id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Base class for shared TIoMapResolver services, used by several derivations.
|
// Base class for shared TIoMapResolver services, used by several derivations.
|
||||||
struct TDefaultIoResolverBase : public glslang::TIoMapResolver {
|
struct TDefaultIoResolverBase : public glslang::TIoMapResolver {
|
||||||
public:
|
public:
|
||||||
|
|
@ -267,29 +189,6 @@ protected:
|
||||||
|
|
||||||
typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
|
typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
|
||||||
|
|
||||||
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
|
|
||||||
// when use vc++, the sort function will call :
|
|
||||||
// pair& operator=(const pair<_Other1, _Other2>& _Right)
|
|
||||||
// {
|
|
||||||
// first = _Right.first;
|
|
||||||
// second = _Right.second;
|
|
||||||
// return (*this);
|
|
||||||
// }
|
|
||||||
// that will make a const type handing on left.
|
|
||||||
// override this function can avoid a compiler error.
|
|
||||||
// In the future, if the vc++ compiler can handle such a situation,
|
|
||||||
// this part of the code will be removed.
|
|
||||||
struct TVarLivePair : std::pair<const TString, TVarEntryInfo> {
|
|
||||||
TVarLivePair(const std::pair<const TString, TVarEntryInfo>& _Right) : pair(_Right.first, _Right.second) {}
|
|
||||||
TVarLivePair& operator=(const TVarLivePair& _Right) {
|
|
||||||
const_cast<TString&>(first) = _Right.first;
|
|
||||||
second = _Right.second;
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
TVarLivePair(const TVarLivePair& src) : pair(src) { }
|
|
||||||
};
|
|
||||||
typedef std::vector<TVarLivePair> TVarLiveVector;
|
|
||||||
|
|
||||||
// I/O mapper
|
// I/O mapper
|
||||||
class TIoMapper {
|
class TIoMapper {
|
||||||
public:
|
public:
|
||||||
|
|
@ -303,34 +202,8 @@ public:
|
||||||
// I/O mapper for GLSL
|
// I/O mapper for GLSL
|
||||||
class TGlslIoMapper : public TIoMapper {
|
class TGlslIoMapper : public TIoMapper {
|
||||||
public:
|
public:
|
||||||
TGlslIoMapper() {
|
TGlslIoMapper();
|
||||||
memset(inVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
virtual ~TGlslIoMapper();
|
||||||
memset(outVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
|
||||||
memset(uniformVarMap, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
|
|
||||||
memset(intermediates, 0, sizeof(TIntermediate*) * (EShLangCount + 1));
|
|
||||||
profile = ENoProfile;
|
|
||||||
version = 0;
|
|
||||||
autoPushConstantMaxSize = 128;
|
|
||||||
autoPushConstantBlockPacking = ElpStd430;
|
|
||||||
}
|
|
||||||
virtual ~TGlslIoMapper() {
|
|
||||||
for (size_t stage = 0; stage < EShLangCount; stage++) {
|
|
||||||
if (inVarMaps[stage] != nullptr) {
|
|
||||||
delete inVarMaps[stage];
|
|
||||||
inVarMaps[stage] = nullptr;
|
|
||||||
}
|
|
||||||
if (outVarMaps[stage] != nullptr) {
|
|
||||||
delete outVarMaps[stage];
|
|
||||||
outVarMaps[stage] = nullptr;
|
|
||||||
}
|
|
||||||
if (uniformVarMap[stage] != nullptr) {
|
|
||||||
delete uniformVarMap[stage];
|
|
||||||
uniformVarMap[stage] = nullptr;
|
|
||||||
}
|
|
||||||
if (intermediates[stage] != nullptr)
|
|
||||||
intermediates[stage] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If set, the uniform block with the given name will be changed to be backed by
|
// If set, the uniform block with the given name will be changed to be backed by
|
||||||
// push_constant if it's size is <= maxSize
|
// push_constant if it's size is <= maxSize
|
||||||
void setAutoPushConstantBlock(const char* name, unsigned int maxSize, TLayoutPacking packing) {
|
void setAutoPushConstantBlock(const char* name, unsigned int maxSize, TLayoutPacking packing) {
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "TestFixture.h"
|
#include "TestFixture.h"
|
||||||
|
|
||||||
|
#include "glslang/MachineIndependent/localintermediate.h"
|
||||||
#include "glslang/MachineIndependent/iomapper.h"
|
#include "glslang/MachineIndependent/iomapper.h"
|
||||||
#include "glslang/MachineIndependent/reflection.h"
|
#include "glslang/MachineIndependent/reflection.h"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue