Skip to content

Commit a0b5136

Browse files
committed
Make TVarEntryInfo part of the public API in ShaderLang.h
1 parent 42e0389 commit a0b5136

2 files changed

Lines changed: 85 additions & 79 deletions

File tree

glslang/MachineIndependent/iomapper.cpp

Lines changed: 36 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -71,83 +71,43 @@ static int getLayoutBindingLimit(bool relaxSetBindingLimits)
7171
return relaxSetBindingLimits ? INT_MAX : int(TQualifier::layoutBindingEnd);
7272
}
7373

74-
struct TVarEntryInfo {
75-
long long id;
76-
TIntermSymbol* symbol;
77-
bool live;
78-
TLayoutPacking upgradedToPushConstantPacking; // ElpNone means it hasn't been upgraded
79-
int newBinding;
80-
int newSet;
81-
int newLocation;
82-
int newComponent;
83-
int newIndex;
84-
EShLanguage stage;
74+
bool TVarEntryInfo::TOrderByPriority::operator()(const TVarEntryInfo& l, const TVarEntryInfo& r)
75+
{
76+
const TQualifier& lq = l.symbol->getQualifier();
77+
const TQualifier& rq = r.symbol->getQualifier();
78+
79+
// simple rules:
80+
// has binding gives 2 points
81+
// has set gives 1 point
82+
// who has the most points is more important.
83+
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
84+
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
85+
86+
if (lPoints == rPoints)
87+
return l.id < r.id;
88+
return lPoints > rPoints;
89+
}
8590

86-
void clearNewAssignments() {
87-
upgradedToPushConstantPacking = ElpNone;
88-
newBinding = -1;
89-
newSet = -1;
90-
newLocation = -1;
91-
newComponent = -1;
92-
newIndex = -1;
93-
}
94-
95-
struct TOrderById {
96-
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
97-
};
98-
99-
struct TOrderByPriority {
100-
// ordering:
101-
// 1) has both binding and set
102-
// 2) has binding but no set
103-
// 3) has no binding but set
104-
// 4) has no binding and no set
105-
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
106-
const TQualifier& lq = l.symbol->getQualifier();
107-
const TQualifier& rq = r.symbol->getQualifier();
108-
109-
// simple rules:
110-
// has binding gives 2 points
111-
// has set gives 1 point
112-
// who has the most points is more important.
113-
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
114-
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
115-
116-
if (lPoints == rPoints)
117-
return l.id < r.id;
118-
return lPoints > rPoints;
119-
}
120-
};
121-
122-
struct TOrderByPriorityAndLive {
123-
// ordering:
124-
// 1) do live variables first
125-
// 2) has both binding and set
126-
// 3) has binding but no set
127-
// 4) has no binding but set
128-
// 5) has no binding and no set
129-
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
130-
131-
const TQualifier& lq = l.symbol->getQualifier();
132-
const TQualifier& rq = r.symbol->getQualifier();
133-
134-
// simple rules:
135-
// has binding gives 2 points
136-
// has set gives 1 point
137-
// who has the most points is more important.
138-
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
139-
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
140-
141-
if (l.live != r.live)
142-
return l.live > r.live;
143-
144-
if (lPoints != rPoints)
145-
return lPoints > rPoints;
146-
147-
return l.id < r.id;
148-
}
149-
};
150-
};
91+
bool TVarEntryInfo::TOrderByPriorityAndLive::operator()(const TVarEntryInfo& l, const TVarEntryInfo& r)
92+
{
93+
const TQualifier& lq = l.symbol->getQualifier();
94+
const TQualifier& rq = r.symbol->getQualifier();
95+
96+
// simple rules:
97+
// has binding gives 2 points
98+
// has set gives 1 point
99+
// who has the most points is more important.
100+
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
101+
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
102+
103+
if (l.live != r.live)
104+
return l.live > r.live;
105+
106+
if (lPoints != rPoints)
107+
return lPoints > rPoints;
108+
109+
return l.id < r.id;
110+
}
151111

152112
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
153113
// when use vc++, the sort function will call :

glslang/Public/ShaderLang.h

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,55 @@ class GLSLANG_EXPORT TObjectReflection {
783783
const TType* type;
784784
};
785785

786-
class TReflection;
787-
class TIoMapper;
788-
struct TVarEntryInfo;
786+
class TReflection;
787+
class TIoMapper;
788+
class TIntermSymbol;
789+
790+
struct GLSLANG_EXPORT TVarEntryInfo {
791+
long long id;
792+
TIntermSymbol* symbol;
793+
bool live;
794+
TLayoutPacking upgradedToPushConstantPacking; // ElpNone means it hasn't been upgraded
795+
int newBinding;
796+
int newSet;
797+
int newLocation;
798+
int newComponent;
799+
int newIndex;
800+
EShLanguage stage;
801+
802+
void clearNewAssignments() {
803+
upgradedToPushConstantPacking = ElpNone;
804+
newBinding = -1;
805+
newSet = -1;
806+
newLocation = -1;
807+
newComponent = -1;
808+
newIndex = -1;
809+
}
810+
811+
struct TOrderById {
812+
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
813+
};
814+
815+
struct TOrderByPriority {
816+
// ordering:
817+
// 1) has both binding and set
818+
// 2) has binding but no set
819+
// 3) has no binding but set
820+
// 4) has no binding and no set
821+
bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r);
822+
};
823+
824+
struct TOrderByPriorityAndLive {
825+
// ordering:
826+
// 1) do live variables first
827+
// 2) has both binding and set
828+
// 3) has binding but no set
829+
// 4) has no binding but set
830+
// 5) has no binding and no set
831+
bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r);
832+
};
833+
};
834+
789835

790836
// Allows to customize the binding layout after linking.
791837
// All used uniform variables will invoke at least validateBinding.

0 commit comments

Comments
 (0)