gfx/angle/src/compiler/VariableInfo.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

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

mercurial