zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VariableInfo.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
8 
10 {
12  stream << "[" << index << "]";
13  return stream.str();
14 }
15 
16 // Returns the data type for an attribute or uniform.
18 {
19  switch (type.getBasicType()) {
20  case EbtFloat:
21  if (type.isMatrix()) {
22  switch (type.getNominalSize()) {
23  case 2: return SH_FLOAT_MAT2;
24  case 3: return SH_FLOAT_MAT3;
25  case 4: return SH_FLOAT_MAT4;
26  default: UNREACHABLE();
27  }
28  } else if (type.isVector()) {
29  switch (type.getNominalSize()) {
30  case 2: return SH_FLOAT_VEC2;
31  case 3: return SH_FLOAT_VEC3;
32  case 4: return SH_FLOAT_VEC4;
33  default: UNREACHABLE();
34  }
35  } else {
36  return SH_FLOAT;
37  }
38  case EbtInt:
39  if (type.isMatrix()) {
40  UNREACHABLE();
41  } else if (type.isVector()) {
42  switch (type.getNominalSize()) {
43  case 2: return SH_INT_VEC2;
44  case 3: return SH_INT_VEC3;
45  case 4: return SH_INT_VEC4;
46  default: UNREACHABLE();
47  }
48  } else {
49  return SH_INT;
50  }
51  case EbtBool:
52  if (type.isMatrix()) {
53  UNREACHABLE();
54  } else if (type.isVector()) {
55  switch (type.getNominalSize()) {
56  case 2: return SH_BOOL_VEC2;
57  case 3: return SH_BOOL_VEC3;
58  case 4: return SH_BOOL_VEC4;
59  default: UNREACHABLE();
60  }
61  } else {
62  return SH_BOOL;
63  }
64  case EbtSampler2D: return SH_SAMPLER_2D;
65  case EbtSamplerCube: return SH_SAMPLER_CUBE;
68  default: UNREACHABLE();
69  }
70  return SH_NONE;
71 }
72 
73 static void getBuiltInVariableInfo(const TType& type,
74  const TString& name,
75  const TString& mappedName,
76  TVariableInfoList& infoList);
77 static void getUserDefinedVariableInfo(const TType& type,
78  const TString& name,
79  const TString& mappedName,
80  TVariableInfoList& infoList,
81  ShHashFunction64 hashFunction);
82 
83 // Returns info for an attribute or uniform.
84 static void getVariableInfo(const TType& type,
85  const TString& name,
86  const TString& mappedName,
87  TVariableInfoList& infoList,
88  ShHashFunction64 hashFunction)
89 {
90  if (type.getBasicType() == EbtStruct) {
91  if (type.isArray()) {
92  for (int i = 0; i < type.getArraySize(); ++i) {
93  TString lname = name + arrayBrackets(i);
94  TString lmappedName = mappedName + arrayBrackets(i);
95  getUserDefinedVariableInfo(type, lname, lmappedName, infoList, hashFunction);
96  }
97  } else {
98  getUserDefinedVariableInfo(type, name, mappedName, infoList, hashFunction);
99  }
100  } else {
101  getBuiltInVariableInfo(type, name, mappedName, infoList);
102  }
103 }
104 
106  const TString& name,
107  const TString& mappedName,
108  TVariableInfoList& infoList)
109 {
110  ASSERT(type.getBasicType() != EbtStruct);
111 
112  TVariableInfo varInfo;
113  if (type.isArray()) {
114  varInfo.name = (name + "[0]").c_str();
115  varInfo.mappedName = (mappedName + "[0]").c_str();
116  varInfo.size = type.getArraySize();
117  } else {
118  varInfo.name = name.c_str();
119  varInfo.mappedName = mappedName.c_str();
120  varInfo.size = 1;
121  }
122  varInfo.type = getVariableDataType(type);
123  infoList.push_back(varInfo);
124 }
125 
127  const TString& name,
128  const TString& mappedName,
129  TVariableInfoList& infoList,
130  ShHashFunction64 hashFunction)
131 {
132  ASSERT(type.getBasicType() == EbtStruct);
133 
134  const TFieldList& fields = type.getStruct()->fields();
135  for (size_t i = 0; i < fields.size(); ++i) {
136  const TType& fieldType = *(fields[i]->type());
137  const TString& fieldName = fields[i]->name();
138  getVariableInfo(fieldType,
139  name + "." + fieldName,
140  mappedName + "." + TIntermTraverser::hash(fieldName, hashFunction),
141  infoList,
142  hashFunction);
143  }
144 }
145 
147 {
148 }
149 
151  : type(type),
152  size(size)
153 {
154 }
155 
157  TVariableInfoList& uniforms,
158  ShHashFunction64 hashFunction)
159  : mAttribs(attribs),
160  mUniforms(uniforms),
161  mHashFunction(hashFunction)
162 {
163 }
164 
165 // We are only interested in attribute and uniform variable declaration.
167 {
168 }
169 
171 {
172 }
173 
175 {
176  return false;
177 }
178 
180 {
181  return false;
182 }
183 
185 {
186  return false;
187 }
188 
190 {
191  bool visitChildren = false;
192 
193  switch (node->getOp())
194  {
195  case EOpSequence:
196  // We need to visit sequence children to get to variable declarations.
197  visitChildren = true;
198  break;
199  case EOpDeclaration: {
200  const TIntermSequence& sequence = node->getSequence();
201  TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
202  if (qualifier == EvqAttribute || qualifier == EvqUniform)
203  {
204  TVariableInfoList& infoList = qualifier == EvqAttribute ?
205  mAttribs : mUniforms;
206  for (TIntermSequence::const_iterator i = sequence.begin();
207  i != sequence.end(); ++i)
208  {
209  const TIntermSymbol* variable = (*i)->getAsSymbolNode();
210  // The only case in which the sequence will not contain a
211  // TIntermSymbol node is initialization. It will contain a
212  // TInterBinary node in that case. Since attributes and unifroms
213  // cannot be initialized in a shader, we must have only
214  // TIntermSymbol nodes in the sequence.
215  ASSERT(variable != NULL);
216  TString processedSymbol;
217  if (mHashFunction == NULL)
218  processedSymbol = variable->getSymbol();
219  else
220  processedSymbol = TIntermTraverser::hash(variable->getOriginalSymbol(), mHashFunction);
221  getVariableInfo(variable->getType(),
222  variable->getOriginalSymbol(),
223  processedSymbol,
224  infoList,
225  mHashFunction);
226  }
227  }
228  break;
229  }
230  default: break;
231  }
232 
233  return visitChildren;
234 }
235 
237 {
238  return false;
239 }
240 
242 {
243  return false;
244 }
245 
Visit
Definition: intermediate.h:524
TOperator getOp() const
Definition: intermediate.h:389
TQualifier
Definition: BaseTypes.h:81
TIntermSequence & getSequence()
Definition: intermediate.h:469
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
const TString & getOriginalSymbol() const
Definition: intermediate.h:354
#define NULL
Definition: ftobjs.h:61
virtual TIntermSymbol * getAsSymbolNode()
Definition: intermediate.h:357
khronos_uint64_t(* ShHashFunction64)(const char *, size_t)
Definition: ShaderLang.h:197
GLuint GLuint stream
Definition: glew.h:6573
ShDataType
Definition: ShaderLang.h:88
virtual bool visitBinary(Visit, TIntermBinary *)
TBasicType getBasicType() const
Definition: Types.h:108
int getNominalSize() const
Definition: Types.h:118
EGLImageKHR EGLint * name
Definition: eglext.h:284
GLenum GLenum variable
Definition: glew.h:12631
Definition: Types.h:93
const GLint * attribs
Definition: glew.h:13064
CollectAttribsUniforms(TVariableInfoList &attribs, TVariableInfoList &uniforms, ShHashFunction64 hashFunction)
bool isArray() const
Definition: Types.h:162
static void getUserDefinedVariableInfo(const TType &type, const TString &name, const TString &mappedName, TVariableInfoList &infoList, ShHashFunction64 hashFunction)
virtual bool visitAggregate(Visit, TIntermAggregate *)
#define ASSERT(expression)
Definition: debug.h:36
static void getBuiltInVariableInfo(const TType &type, const TString &name, const TString &mappedName, TVariableInfoList &infoList)
virtual void visitSymbol(TIntermSymbol *)
std::basic_ostringstream< char, std::char_traits< char >, TStringAllocator > TStringStream
Definition: Common.h:42
const TType & getType() const
Definition: intermediate.h:251
static TString hash(const TString &name, ShHashFunction64 hashFunction)
#define UNREACHABLE()
Definition: debug.h:47
GLuint index
Definition: glew.h:1800
bool isVector() const
Definition: Types.h:167
virtual bool visitUnary(Visit, TIntermUnary *)
static TString arrayBrackets(int index)
Definition: VariableInfo.cpp:9
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
virtual bool visitBranch(Visit, TIntermBranch *)
TPersistString name
Definition: VariableInfo.h:19
virtual bool visitLoop(Visit, TIntermLoop *)
virtual bool visitSelection(Visit, TIntermSelection *)
int getArraySize() const
Definition: Types.h:163
Definition: Common.h:59
bool isMatrix() const
Definition: Types.h:159
static ShDataType getVariableDataType(const TType &type)
std::vector< TVariableInfo > TVariableInfoList
Definition: VariableInfo.h:24
const TFieldList & fields() const
Definition: Types.h:57
TStructure * getStruct() const
Definition: Types.h:170
const TString & getSymbol() const
Definition: intermediate.h:349
int i
Definition: pngrutil.c:1377
static void getVariableInfo(const TType &type, const TString &name, const TString &mappedName, TVariableInfoList &infoList, ShHashFunction64 hashFunction)
virtual void visitConstantUnion(TIntermConstantUnion *)
GLsizei size
Definition: gl2ext.h:1467