blob: ea258559be7707c8d35a1fa0be9c15ae73bfc17c [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
Nicolas Capens16004fc2014-06-11 11:29:11 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
zmo@google.com5601ea02011-06-10 18:23:25 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang17732822013-08-29 13:46:49 -04007#include "compiler/translator/OutputGLSLBase.h"
Olli Etuahod57e0db2015-04-24 15:05:08 +03008
Shaob5cc1192017-07-06 10:47:20 +08009#include "angle_gl.h"
Olli Etuahod57e0db2015-04-24 15:05:08 +030010#include "common/debug.h"
Olli Etuaho56a2f952016-12-08 12:16:27 +000011#include "common/mathutil.h"
Olli Etuahocccf2b02017-07-05 14:50:54 +030012#include "compiler/translator/Compiler.h"
Olli Etuaho96f6adf2017-08-16 11:18:54 +030013#include "compiler/translator/util.h"
zmo@google.com5601ea02011-06-10 18:23:25 +000014
daniel@transgaming.com773ff742013-01-11 04:12:51 +000015#include <cfloat>
daniel@transgaming.com6c1203f2013-01-11 04:12:43 +000016
Jamie Madill45bcc782016-11-07 13:58:48 -050017namespace sh
18{
19
zmo@google.com5601ea02011-06-10 18:23:25 +000020namespace
21{
zmo@google.com5601ea02011-06-10 18:23:25 +000022
Zhenyao Mo9eedea02014-05-12 16:02:35 -070023bool isSingleStatement(TIntermNode *node)
24{
Olli Etuaho336b1472016-10-05 16:37:55 +010025 if (node->getAsFunctionDefinition())
zmo@google.com5601ea02011-06-10 18:23:25 +000026 {
Olli Etuaho336b1472016-10-05 16:37:55 +010027 return false;
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010028 }
29 else if (node->getAsBlock())
30 {
31 return false;
zmo@google.com5601ea02011-06-10 18:23:25 +000032 }
Olli Etuaho57961272016-09-14 13:57:46 +030033 else if (node->getAsIfElseNode())
zmo@google.com5601ea02011-06-10 18:23:25 +000034 {
Olli Etuahod0bad2c2016-09-09 18:01:16 +030035 return false;
zmo@google.com5601ea02011-06-10 18:23:25 +000036 }
37 else if (node->getAsLoopNode())
38 {
39 return false;
40 }
Olli Etuaho01cd8af2015-02-20 10:39:20 +020041 else if (node->getAsSwitchNode())
42 {
43 return false;
44 }
45 else if (node->getAsCaseNode())
46 {
47 return false;
48 }
zmo@google.com5601ea02011-06-10 18:23:25 +000049 return true;
50}
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080051
Olli Etuaho43364892017-02-13 16:00:12 +000052class CommaSeparatedListItemPrefixGenerator
53{
54 public:
55 CommaSeparatedListItemPrefixGenerator() : mFirst(true) {}
56 private:
57 bool mFirst;
58
59 friend TInfoSinkBase &operator<<(TInfoSinkBase &out,
60 CommaSeparatedListItemPrefixGenerator &gen);
61};
62
63TInfoSinkBase &operator<<(TInfoSinkBase &out, CommaSeparatedListItemPrefixGenerator &gen)
64{
65 if (gen.mFirst)
66 {
67 gen.mFirst = false;
68 }
69 else
70 {
71 out << ", ";
72 }
73 return out;
74}
75
zmo@google.com5601ea02011-06-10 18:23:25 +000076} // namespace
77
Zhenyao Mo9eedea02014-05-12 16:02:35 -070078TOutputGLSLBase::TOutputGLSLBase(TInfoSinkBase &objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000079 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000080 ShHashFunction64 hashFunction,
Zhenyao Mo9eedea02014-05-12 16:02:35 -070081 NameMap &nameMap,
Olli Etuahoa5e693a2017-07-13 16:07:26 +030082 TSymbolTable *symbolTable,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000083 sh::GLenum shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080084 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080085 ShShaderOutput output,
86 ShCompileOptions compileOptions)
Olli Etuahoa5e693a2017-07-13 16:07:26 +030087 : TIntermTraverser(true, true, true, symbolTable),
zmo@google.com5601ea02011-06-10 18:23:25 +000088 mObjSink(objSink),
Olli Etuaho39f74df2017-11-20 16:09:57 +020089 mDeclaringVariable(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000090 mClampingStrategy(clampingStrategy),
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000091 mHashFunction(hashFunction),
92 mNameMap(nameMap),
Qiankun Miao89dd8f32016-11-09 12:59:30 +000093 mShaderType(shaderType),
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080094 mShaderVersion(shaderVersion),
Qiankun Miao705a9192016-08-29 10:05:27 +080095 mOutput(output),
96 mCompileOptions(compileOptions)
zmo@google.com5601ea02011-06-10 18:23:25 +000097{
98}
99
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800100void TOutputGLSLBase::writeInvariantQualifier(const TType &type)
101{
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000102 if (!sh::RemoveInvariant(mShaderType, mShaderVersion, mOutput, mCompileOptions))
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800103 {
104 TInfoSinkBase &out = objSink();
105 out << "invariant ";
106 }
107}
108
Olli Etuaho56a2f952016-12-08 12:16:27 +0000109void TOutputGLSLBase::writeFloat(TInfoSinkBase &out, float f)
110{
111 if ((gl::isInf(f) || gl::isNaN(f)) && mShaderVersion >= 300)
112 {
113 out << "uintBitsToFloat(" << gl::bitCast<uint32_t>(f) << "u)";
114 }
115 else
116 {
117 out << std::min(FLT_MAX, std::max(-FLT_MAX, f));
118 }
119}
120
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500121void TOutputGLSLBase::writeTriplet(Visit visit,
122 const char *preStr,
123 const char *inStr,
124 const char *postStr)
zmo@google.com5601ea02011-06-10 18:23:25 +0000125{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700126 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000127 if (visit == PreVisit && preStr)
zmo@google.com5601ea02011-06-10 18:23:25 +0000128 out << preStr;
zmo@google.com5601ea02011-06-10 18:23:25 +0000129 else if (visit == InVisit && inStr)
zmo@google.com5601ea02011-06-10 18:23:25 +0000130 out << inStr;
zmo@google.com5601ea02011-06-10 18:23:25 +0000131 else if (visit == PostVisit && postStr)
zmo@google.com5601ea02011-06-10 18:23:25 +0000132 out << postStr;
zmo@google.com5601ea02011-06-10 18:23:25 +0000133}
134
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500135void TOutputGLSLBase::writeBuiltInFunctionTriplet(Visit visit,
Olli Etuahoe1805592017-01-02 16:41:20 +0000136 TOperator op,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500137 bool useEmulatedFunction)
zmo@google.com5601ea02011-06-10 18:23:25 +0000138{
Olli Etuahod68924e2017-01-02 17:34:40 +0000139 TInfoSinkBase &out = objSink();
140 if (visit == PreVisit)
Olli Etuahoe1805592017-01-02 16:41:20 +0000141 {
Olli Etuahod68924e2017-01-02 17:34:40 +0000142 const char *opStr(GetOperatorString(op));
143 if (useEmulatedFunction)
144 {
145 BuiltInFunctionEmulator::WriteEmulatedFunctionName(out, opStr);
146 }
147 else
148 {
149 out << opStr;
150 }
151 out << "(";
Olli Etuahoe1805592017-01-02 16:41:20 +0000152 }
Olli Etuahod68924e2017-01-02 17:34:40 +0000153 else
154 {
155 writeTriplet(visit, nullptr, ", ", ")");
156 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700157}
158
Jamie Madill2a9e1072017-09-22 11:31:57 -0400159void TOutputGLSLBase::writeLayoutQualifier(TIntermTyped *variable)
Olli Etuahoae69d7e2015-10-07 17:19:50 +0300160{
Jamie Madill2a9e1072017-09-22 11:31:57 -0400161 const TType &type = variable->getType();
162
Martin Radev2cc85b32016-08-05 16:22:53 +0300163 if (!NeedsToWriteLayoutQualifier(type))
164 {
165 return;
166 }
167
168 TInfoSinkBase &out = objSink();
169 const TLayoutQualifier &layoutQualifier = type.getLayoutQualifier();
170 out << "layout(";
171
Olli Etuaho43364892017-02-13 16:00:12 +0000172 CommaSeparatedListItemPrefixGenerator listItemPrefix;
173
Jiawei Shao4cc89e22017-08-31 14:25:54 +0800174 if (type.getQualifier() == EvqFragmentOut || type.getQualifier() == EvqVertexIn ||
175 IsVarying(type.getQualifier()))
Olli Etuahoae69d7e2015-10-07 17:19:50 +0300176 {
Olli Etuahoae69d7e2015-10-07 17:19:50 +0300177 if (layoutQualifier.location >= 0)
178 {
Olli Etuaho43364892017-02-13 16:00:12 +0000179 out << listItemPrefix << "location = " << layoutQualifier.location;
Olli Etuahoae69d7e2015-10-07 17:19:50 +0300180 }
181 }
Martin Radev2cc85b32016-08-05 16:22:53 +0300182
Andrei Volykhina5527072017-03-22 16:46:30 +0300183 if (type.getQualifier() == EvqFragmentOut)
184 {
185 if (layoutQualifier.yuv == true)
186 {
187 out << listItemPrefix << "yuv";
188 }
189 }
190
Olli Etuaho43364892017-02-13 16:00:12 +0000191 if (IsOpaqueType(type.getBasicType()))
Martin Radev2cc85b32016-08-05 16:22:53 +0300192 {
Olli Etuaho43364892017-02-13 16:00:12 +0000193 if (layoutQualifier.binding >= 0)
194 {
195 out << listItemPrefix << "binding = " << layoutQualifier.binding;
196 }
197 }
198
199 if (IsImage(type.getBasicType()))
200 {
201 if (layoutQualifier.imageInternalFormat != EiifUnspecified)
202 {
203 ASSERT(type.getQualifier() == EvqTemporary || type.getQualifier() == EvqUniform);
204 out << listItemPrefix
205 << getImageInternalFormatString(layoutQualifier.imageInternalFormat);
206 }
Martin Radev2cc85b32016-08-05 16:22:53 +0300207 }
208
jchen1005c31da2017-07-18 16:11:39 +0800209 if (IsAtomicCounter(type.getBasicType()))
210 {
211 out << listItemPrefix << "offset = " << layoutQualifier.offset;
212 }
213
Martin Radev2cc85b32016-08-05 16:22:53 +0300214 out << ") ";
Olli Etuahoae69d7e2015-10-07 17:19:50 +0300215}
216
Luc Ferronf1d3c202018-04-16 07:44:27 -0400217void TOutputGLSLBase::writeQualifier(TQualifier qualifier, const TSymbol *symbol)
218{
219 const char *result = mapQualifierToString(qualifier);
220 if (result && result[0] != '\0')
221 {
222 objSink() << result << " ";
223 }
224}
225
226const char *TOutputGLSLBase::mapQualifierToString(TQualifier qualifier)
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800227{
228 if (sh::IsGLSL410OrOlder(mOutput) && mShaderVersion >= 300 &&
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000229 (mCompileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0)
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800230 {
231 switch (qualifier)
232 {
233 // The return string is consistent with sh::getQualifierString() from
234 // BaseTypes.h minus the "centroid" keyword.
235 case EvqCentroid:
236 return "";
237 case EvqCentroidIn:
238 return "smooth in";
239 case EvqCentroidOut:
240 return "smooth out";
241 default:
242 break;
243 }
244 }
245 if (sh::IsGLSL130OrNewer(mOutput))
246 {
247 switch (qualifier)
248 {
249 case EvqAttribute:
250 return "in";
251 case EvqVaryingIn:
252 return "in";
253 case EvqVaryingOut:
254 return "out";
255 default:
256 break;
257 }
258 }
259 return sh::getQualifierString(qualifier);
260}
261
Jamie Madillaed1b562018-04-17 11:47:46 -0400262void TOutputGLSLBase::writeVariableType(const TType &type, const TSymbol *symbol)
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700263{
Qiankun Miao705a9192016-08-29 10:05:27 +0800264 TQualifier qualifier = type.getQualifier();
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500265 TInfoSinkBase &out = objSink();
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800266 if (type.isInvariant())
Olli Etuaho214c2d82015-04-27 14:49:13 +0300267 {
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800268 writeInvariantQualifier(type);
Olli Etuaho214c2d82015-04-27 14:49:13 +0300269 }
Geoff Langbdcc54a2015-09-02 13:09:48 -0400270 if (type.getBasicType() == EbtInterfaceBlock)
271 {
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200272 const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
Geoff Langbdcc54a2015-09-02 13:09:48 -0400273 declareInterfaceBlockLayout(interfaceBlock);
274 }
Jamie Madill3b5c2da2014-08-19 15:23:32 -0400275 if (qualifier != EvqTemporary && qualifier != EvqGlobal)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400276 {
Luc Ferronf1d3c202018-04-16 07:44:27 -0400277 writeQualifier(qualifier, symbol);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400278 }
Martin Radev2cc85b32016-08-05 16:22:53 +0300279
280 const TMemoryQualifier &memoryQualifier = type.getMemoryQualifier();
281 if (memoryQualifier.readonly)
282 {
283 ASSERT(IsImage(type.getBasicType()));
284 out << "readonly ";
285 }
286
287 if (memoryQualifier.writeonly)
288 {
289 ASSERT(IsImage(type.getBasicType()));
290 out << "writeonly ";
291 }
292
Martin Radev049edfa2016-11-11 14:35:37 +0200293 if (memoryQualifier.coherent)
294 {
295 ASSERT(IsImage(type.getBasicType()));
296 out << "coherent ";
297 }
298
299 if (memoryQualifier.restrictQualifier)
300 {
301 ASSERT(IsImage(type.getBasicType()));
302 out << "restrict ";
303 }
304
305 if (memoryQualifier.volatileQualifier)
306 {
307 ASSERT(IsImage(type.getBasicType()));
308 out << "volatile ";
309 }
310
zmo@google.com5601ea02011-06-10 18:23:25 +0000311 // Declare the struct if we have not done so already.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700312 if (type.getBasicType() == EbtStruct && !structDeclared(type.getStruct()))
zmo@google.com5601ea02011-06-10 18:23:25 +0000313 {
Olli Etuahobd3cd502017-11-03 15:48:52 +0200314 const TStructure *structure = type.getStruct();
Jamie Madill01f85ac2014-06-06 11:55:04 -0400315
316 declareStruct(structure);
zmo@google.com5601ea02011-06-10 18:23:25 +0000317 }
Geoff Langbdcc54a2015-09-02 13:09:48 -0400318 else if (type.getBasicType() == EbtInterfaceBlock)
319 {
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200320 const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
Geoff Langbdcc54a2015-09-02 13:09:48 -0400321 declareInterfaceBlock(interfaceBlock);
322 }
zmo@google.com5601ea02011-06-10 18:23:25 +0000323 else
324 {
325 if (writeVariablePrecision(type.getPrecision()))
326 out << " ";
327 out << getTypeName(type);
328 }
329}
330
Olli Etuahod4bd9632018-03-08 16:32:44 +0200331void TOutputGLSLBase::writeFunctionParameters(const TFunction *func)
zmo@google.com5601ea02011-06-10 18:23:25 +0000332{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700333 TInfoSinkBase &out = objSink();
Olli Etuahod4bd9632018-03-08 16:32:44 +0200334 size_t paramCount = func->getParamCount();
335 for (size_t i = 0; i < paramCount; ++i)
zmo@google.com5601ea02011-06-10 18:23:25 +0000336 {
Olli Etuahod4bd9632018-03-08 16:32:44 +0200337 const TVariable *param = func->getParam(i);
338 const TType &type = param->getType();
Jamie Madillaed1b562018-04-17 11:47:46 -0400339 writeVariableType(type, param);
zmo@google.com5601ea02011-06-10 18:23:25 +0000340
Olli Etuahod4bd9632018-03-08 16:32:44 +0200341 if (param->symbolType() != SymbolType::Empty)
342 out << " " << hashName(param);
zmo@google.com5601ea02011-06-10 18:23:25 +0000343 if (type.isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300344 out << ArrayString(type);
zmo@google.com5601ea02011-06-10 18:23:25 +0000345
346 // Put a comma if this is not the last argument.
Olli Etuahod4bd9632018-03-08 16:32:44 +0200347 if (i != paramCount - 1)
zmo@google.com5601ea02011-06-10 18:23:25 +0000348 out << ", ";
349 }
350}
351
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500352const TConstantUnion *TOutputGLSLBase::writeConstantUnion(const TType &type,
353 const TConstantUnion *pConstUnion)
zmo@google.com5601ea02011-06-10 18:23:25 +0000354{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700355 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000356
357 if (type.getBasicType() == EbtStruct)
358 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700359 const TStructure *structure = type.getStruct();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200360 out << hashName(structure) << "(";
Jamie Madill98493dd2013-07-08 14:39:03 -0400361
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700362 const TFieldList &fields = structure->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -0400363 for (size_t i = 0; i < fields.size(); ++i)
zmo@google.com5601ea02011-06-10 18:23:25 +0000364 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700365 const TType *fieldType = fields[i]->type();
Yunchao He4f285442017-04-21 12:15:49 +0800366 ASSERT(fieldType != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +0000367 pConstUnion = writeConstantUnion(*fieldType, pConstUnion);
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700368 if (i != fields.size() - 1)
369 out << ", ";
zmo@google.com5601ea02011-06-10 18:23:25 +0000370 }
371 out << ")";
372 }
373 else
374 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500375 size_t size = type.getObjectSize();
zmo@google.com5601ea02011-06-10 18:23:25 +0000376 bool writeType = size > 1;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700377 if (writeType)
378 out << getTypeName(type) << "(";
Jamie Madill94bf7f22013-07-08 13:31:15 -0400379 for (size_t i = 0; i < size; ++i, ++pConstUnion)
zmo@google.com5601ea02011-06-10 18:23:25 +0000380 {
381 switch (pConstUnion->getType())
382 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500383 case EbtFloat:
384 writeFloat(out, pConstUnion->getFConst());
385 break;
386 case EbtInt:
387 out << pConstUnion->getIConst();
388 break;
389 case EbtUInt:
390 out << pConstUnion->getUConst() << "u";
391 break;
392 case EbtBool:
393 out << pConstUnion->getBConst();
394 break;
Andrei Volykhina5527072017-03-22 16:46:30 +0300395 case EbtYuvCscStandardEXT:
396 out << getYuvCscStandardEXTString(pConstUnion->getYuvCscStandardEXTConst());
397 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500398 default:
399 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000400 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700401 if (i != size - 1)
402 out << ", ";
zmo@google.com5601ea02011-06-10 18:23:25 +0000403 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700404 if (writeType)
405 out << ")";
zmo@google.com5601ea02011-06-10 18:23:25 +0000406 }
407 return pConstUnion;
408}
409
Olli Etuahoe92507b2016-07-04 11:20:10 +0300410void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type)
Olli Etuahof40319e2015-03-10 14:33:00 +0200411{
412 TInfoSinkBase &out = objSink();
413 if (visit == PreVisit)
414 {
415 if (type.isArray())
416 {
Olli Etuahoe92507b2016-07-04 11:20:10 +0300417 out << getTypeName(type);
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300418 out << ArrayString(type);
Olli Etuahof40319e2015-03-10 14:33:00 +0200419 out << "(";
420 }
421 else
422 {
Olli Etuahoe92507b2016-07-04 11:20:10 +0300423 out << getTypeName(type) << "(";
Olli Etuahof40319e2015-03-10 14:33:00 +0200424 }
425 }
426 else
427 {
428 writeTriplet(visit, nullptr, ", ", ")");
429 }
430}
431
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700432void TOutputGLSLBase::visitSymbol(TIntermSymbol *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000433{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700434 TInfoSinkBase &out = objSink();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200435 out << hashName(&node->variable());
zmo@google.com5601ea02011-06-10 18:23:25 +0000436
Olli Etuaho39f74df2017-11-20 16:09:57 +0200437 if (mDeclaringVariable && node->getType().isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300438 out << ArrayString(node->getType());
zmo@google.com5601ea02011-06-10 18:23:25 +0000439}
440
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700441void TOutputGLSLBase::visitConstantUnion(TIntermConstantUnion *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000442{
Olli Etuahoea22b7a2018-01-04 17:09:11 +0200443 writeConstantUnion(node->getType(), node->getConstantValue());
zmo@google.com5601ea02011-06-10 18:23:25 +0000444}
445
Olli Etuahob6fa0432016-09-28 16:28:05 +0100446bool TOutputGLSLBase::visitSwizzle(Visit visit, TIntermSwizzle *node)
447{
448 TInfoSinkBase &out = objSink();
449 if (visit == PostVisit)
450 {
451 out << ".";
452 node->writeOffsetsAsXYZW(&out);
453 }
454 return true;
455}
456
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700457bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000458{
459 bool visitChildren = true;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700460 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000461 switch (node->getOp())
462 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100463 case EOpComma:
464 writeTriplet(visit, "(", ", ", ")");
465 break;
466 case EOpInitialize:
zmo@google.com5601ea02011-06-10 18:23:25 +0000467 if (visit == InVisit)
468 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100469 out << " = ";
470 // RHS of initialize is not being declared.
Olli Etuaho39f74df2017-11-20 16:09:57 +0200471 mDeclaringVariable = false;
zmo@google.com5601ea02011-06-10 18:23:25 +0000472 }
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100473 break;
474 case EOpAssign:
475 writeTriplet(visit, "(", " = ", ")");
476 break;
477 case EOpAddAssign:
478 writeTriplet(visit, "(", " += ", ")");
479 break;
480 case EOpSubAssign:
481 writeTriplet(visit, "(", " -= ", ")");
482 break;
483 case EOpDivAssign:
484 writeTriplet(visit, "(", " /= ", ")");
485 break;
486 case EOpIModAssign:
487 writeTriplet(visit, "(", " %= ", ")");
488 break;
489 // Notice the fall-through.
490 case EOpMulAssign:
491 case EOpVectorTimesMatrixAssign:
492 case EOpVectorTimesScalarAssign:
493 case EOpMatrixTimesScalarAssign:
494 case EOpMatrixTimesMatrixAssign:
495 writeTriplet(visit, "(", " *= ", ")");
496 break;
497 case EOpBitShiftLeftAssign:
498 writeTriplet(visit, "(", " <<= ", ")");
499 break;
500 case EOpBitShiftRightAssign:
501 writeTriplet(visit, "(", " >>= ", ")");
502 break;
503 case EOpBitwiseAndAssign:
504 writeTriplet(visit, "(", " &= ", ")");
505 break;
506 case EOpBitwiseXorAssign:
507 writeTriplet(visit, "(", " ^= ", ")");
508 break;
509 case EOpBitwiseOrAssign:
510 writeTriplet(visit, "(", " |= ", ")");
511 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000512
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100513 case EOpIndexDirect:
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800514 writeTriplet(visit, nullptr, "[", "]");
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100515 break;
516 case EOpIndexIndirect:
517 if (node->getAddIndexClamp())
518 {
519 if (visit == InVisit)
520 {
521 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
522 out << "[int(clamp(float(";
523 else
524 out << "[webgl_int_clamp(";
525 }
526 else if (visit == PostVisit)
527 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100528 TIntermTyped *left = node->getLeft();
529 TType leftType = left->getType();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700530
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100531 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
Olli Etuahoebee5b32017-11-23 12:56:32 +0200532 out << "), 0.0, float(";
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100533 else
Olli Etuahoebee5b32017-11-23 12:56:32 +0200534 out << ", 0, ";
535
536 if (leftType.isUnsizedArray())
537 {
538 // For runtime-sized arrays in ESSL 3.10 we need to call the length method
539 // to get the length to clamp against. See ESSL 3.10 section 4.1.9. Note
540 // that a runtime-sized array expression is guaranteed not to have side
541 // effects, so it's fine to add the expression to the output twice.
542 ASSERT(mShaderVersion >= 310);
543 ASSERT(!left->hasSideEffects());
544 left->traverse(this);
545 out << ".length() - 1";
546 }
547 else
548 {
549 int maxSize;
550 if (leftType.isArray())
551 {
552 maxSize = static_cast<int>(leftType.getOutermostArraySize()) - 1;
553 }
554 else
555 {
556 maxSize = leftType.getNominalSize() - 1;
557 }
558 out << maxSize;
559 }
560 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
561 out << ")))]";
562 else
563 out << ")]";
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100564 }
565 }
566 else
567 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800568 writeTriplet(visit, nullptr, "[", "]");
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100569 }
570 break;
571 case EOpIndexDirectStruct:
572 if (visit == InVisit)
573 {
574 // Here we are writing out "foo.bar", where "foo" is struct
575 // and "bar" is field. In AST, it is represented as a binary
576 // node, where left child represents "foo" and right child "bar".
577 // The node itself represents ".". The struct field "bar" is
578 // actually stored as an index into TStructure::fields.
579 out << ".";
580 const TStructure *structure = node->getLeft()->getType().getStruct();
581 const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
582 const TField *field = structure->fields()[index->getIConst(0)];
583
Jamie Madillf5557ac2018-06-15 09:46:58 -0400584 out << hashFieldName(field);
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100585 visitChildren = false;
586 }
587 break;
588 case EOpIndexDirectInterfaceBlock:
589 if (visit == InVisit)
590 {
591 out << ".";
592 const TInterfaceBlock *interfaceBlock =
593 node->getLeft()->getType().getInterfaceBlock();
594 const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
595 const TField *field = interfaceBlock->fields()[index->getIConst(0)];
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200596 ASSERT(interfaceBlock->symbolType() == SymbolType::UserDefined ||
597 interfaceBlock->name() == "gl_PerVertex");
Jamie Madillf5557ac2018-06-15 09:46:58 -0400598 out << hashFieldName(field);
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100599 visitChildren = false;
600 }
601 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400602
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100603 case EOpAdd:
604 writeTriplet(visit, "(", " + ", ")");
605 break;
606 case EOpSub:
607 writeTriplet(visit, "(", " - ", ")");
608 break;
609 case EOpMul:
610 writeTriplet(visit, "(", " * ", ")");
611 break;
612 case EOpDiv:
613 writeTriplet(visit, "(", " / ", ")");
614 break;
615 case EOpIMod:
616 writeTriplet(visit, "(", " % ", ")");
617 break;
618 case EOpBitShiftLeft:
619 writeTriplet(visit, "(", " << ", ")");
620 break;
621 case EOpBitShiftRight:
622 writeTriplet(visit, "(", " >> ", ")");
623 break;
624 case EOpBitwiseAnd:
625 writeTriplet(visit, "(", " & ", ")");
626 break;
627 case EOpBitwiseXor:
628 writeTriplet(visit, "(", " ^ ", ")");
629 break;
630 case EOpBitwiseOr:
631 writeTriplet(visit, "(", " | ", ")");
632 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400633
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100634 case EOpEqual:
635 writeTriplet(visit, "(", " == ", ")");
636 break;
637 case EOpNotEqual:
638 writeTriplet(visit, "(", " != ", ")");
639 break;
640 case EOpLessThan:
641 writeTriplet(visit, "(", " < ", ")");
642 break;
643 case EOpGreaterThan:
644 writeTriplet(visit, "(", " > ", ")");
645 break;
646 case EOpLessThanEqual:
647 writeTriplet(visit, "(", " <= ", ")");
648 break;
649 case EOpGreaterThanEqual:
650 writeTriplet(visit, "(", " >= ", ")");
651 break;
daniel@transgaming.com97b16d12013-02-01 03:20:42 +0000652
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100653 // Notice the fall-through.
654 case EOpVectorTimesScalar:
655 case EOpVectorTimesMatrix:
656 case EOpMatrixTimesVector:
657 case EOpMatrixTimesScalar:
658 case EOpMatrixTimesMatrix:
659 writeTriplet(visit, "(", " * ", ")");
660 break;
Olli Etuaho31b5fc62015-01-16 12:13:36 +0200661
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100662 case EOpLogicalOr:
663 writeTriplet(visit, "(", " || ", ")");
664 break;
665 case EOpLogicalXor:
666 writeTriplet(visit, "(", " ^^ ", ")");
667 break;
668 case EOpLogicalAnd:
669 writeTriplet(visit, "(", " && ", ")");
670 break;
671 default:
672 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000673 }
674
675 return visitChildren;
676}
677
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700678bool TOutputGLSLBase::visitUnary(Visit visit, TIntermUnary *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000679{
Olli Etuaho2f7c04a2018-01-25 14:50:37 +0200680 const char *preString = "";
681 const char *postString = ")";
zmo@google.com32e97312011-08-24 01:03:11 +0000682
zmo@google.com5601ea02011-06-10 18:23:25 +0000683 switch (node->getOp())
684 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500685 case EOpNegative:
686 preString = "(-";
687 break;
688 case EOpPositive:
689 preString = "(+";
690 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500691 case EOpLogicalNot:
692 preString = "(!";
693 break;
694 case EOpBitwiseNot:
695 preString = "(~";
696 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000697
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500698 case EOpPostIncrement:
699 preString = "(";
700 postString = "++)";
701 break;
702 case EOpPostDecrement:
703 preString = "(";
704 postString = "--)";
705 break;
706 case EOpPreIncrement:
707 preString = "(++";
708 break;
709 case EOpPreDecrement:
710 preString = "(--";
711 break;
Olli Etuahobb5a7e22017-08-30 13:03:12 +0300712 case EOpArrayLength:
713 preString = "((";
714 postString = ").length())";
715 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000716
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500717 case EOpRadians:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500718 case EOpDegrees:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500719 case EOpSin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500720 case EOpCos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500721 case EOpTan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500722 case EOpAsin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500723 case EOpAcos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500724 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500725 case EOpSinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500726 case EOpCosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500727 case EOpTanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500728 case EOpAsinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500729 case EOpAcosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500730 case EOpAtanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500731 case EOpExp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500732 case EOpLog:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500733 case EOpExp2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500734 case EOpLog2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500735 case EOpSqrt:
Olli Etuahof7f0b8c2018-02-21 20:02:23 +0200736 case EOpInversesqrt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500737 case EOpAbs:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500738 case EOpSign:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500739 case EOpFloor:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500740 case EOpTrunc:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500741 case EOpRound:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500742 case EOpRoundEven:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500743 case EOpCeil:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500744 case EOpFract:
Olli Etuahof7f0b8c2018-02-21 20:02:23 +0200745 case EOpIsnan:
746 case EOpIsinf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500747 case EOpFloatBitsToInt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500748 case EOpFloatBitsToUint:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500749 case EOpIntBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500750 case EOpUintBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500751 case EOpPackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500752 case EOpPackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500753 case EOpPackHalf2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500754 case EOpUnpackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500755 case EOpUnpackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500756 case EOpUnpackHalf2x16:
Olli Etuaho25aef452017-01-29 16:15:44 -0800757 case EOpPackUnorm4x8:
758 case EOpPackSnorm4x8:
759 case EOpUnpackUnorm4x8:
760 case EOpUnpackSnorm4x8:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500761 case EOpLength:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500762 case EOpNormalize:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500763 case EOpDFdx:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500764 case EOpDFdy:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500765 case EOpFwidth:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500766 case EOpTranspose:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500767 case EOpDeterminant:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500768 case EOpInverse:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500769 case EOpAny:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500770 case EOpAll:
Olli Etuahod68924e2017-01-02 17:34:40 +0000771 case EOpLogicalNotComponentWise:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000772 case EOpBitfieldReverse:
773 case EOpBitCount:
774 case EOpFindLSB:
775 case EOpFindMSB:
Olli Etuahod68924e2017-01-02 17:34:40 +0000776 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
777 return true;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500778 default:
779 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000780 }
781
Olli Etuaho2f7c04a2018-01-25 14:50:37 +0200782 writeTriplet(visit, preString, nullptr, postString);
zmo@google.com32e97312011-08-24 01:03:11 +0000783
zmo@google.com5601ea02011-06-10 18:23:25 +0000784 return true;
785}
786
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300787bool TOutputGLSLBase::visitTernary(Visit visit, TIntermTernary *node)
788{
789 TInfoSinkBase &out = objSink();
790 // Notice two brackets at the beginning and end. The outer ones
791 // encapsulate the whole ternary expression. This preserves the
792 // order of precedence when ternary expressions are used in a
793 // compound expression, i.e., c = 2 * (a < b ? 1 : 2).
794 out << "((";
795 node->getCondition()->traverse(this);
796 out << ") ? (";
797 node->getTrueExpression()->traverse(this);
798 out << ") : (";
799 node->getFalseExpression()->traverse(this);
800 out << "))";
801 return false;
802}
803
Olli Etuaho57961272016-09-14 13:57:46 +0300804bool TOutputGLSLBase::visitIfElse(Visit visit, TIntermIfElse *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000805{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700806 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000807
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300808 out << "if (";
809 node->getCondition()->traverse(this);
810 out << ")\n";
zmo@google.com5601ea02011-06-10 18:23:25 +0000811
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300812 visitCodeBlock(node->getTrueBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000813
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300814 if (node->getFalseBlock())
815 {
816 out << "else\n";
817 visitCodeBlock(node->getFalseBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000818 }
819 return false;
820}
821
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200822bool TOutputGLSLBase::visitSwitch(Visit visit, TIntermSwitch *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200823{
Olli Etuaho923ecef2017-10-11 12:01:38 +0300824 ASSERT(node->getStatementList());
825 writeTriplet(visit, "switch (", ") ", nullptr);
826 // The curly braces get written when visiting the statementList aggregate
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200827 return true;
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200828}
829
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200830bool TOutputGLSLBase::visitCase(Visit visit, TIntermCase *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200831{
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200832 if (node->hasCondition())
833 {
834 writeTriplet(visit, "case (", nullptr, "):\n");
835 return true;
836 }
837 else
838 {
839 TInfoSinkBase &out = objSink();
840 out << "default:\n";
841 return false;
842 }
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200843}
844
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100845bool TOutputGLSLBase::visitBlock(Visit visit, TIntermBlock *node)
846{
847 TInfoSinkBase &out = objSink();
848 // Scope the blocks except when at the global scope.
Olli Etuaho4002e922018-04-04 16:55:34 +0300849 if (getCurrentTraversalDepth() > 0)
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100850 {
851 out << "{\n";
852 }
853
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100854 for (TIntermSequence::const_iterator iter = node->getSequence()->begin();
855 iter != node->getSequence()->end(); ++iter)
856 {
857 TIntermNode *curNode = *iter;
858 ASSERT(curNode != nullptr);
859 curNode->traverse(this);
860
861 if (isSingleStatement(curNode))
862 out << ";\n";
863 }
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100864
865 // Scope the blocks except when at the global scope.
Olli Etuaho4002e922018-04-04 16:55:34 +0300866 if (getCurrentTraversalDepth() > 0)
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100867 {
868 out << "}\n";
869 }
870 return false;
871}
872
Olli Etuaho336b1472016-10-05 16:37:55 +0100873bool TOutputGLSLBase::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
874{
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000875 TIntermFunctionPrototype *prototype = node->getFunctionPrototype();
876 prototype->traverse(this);
Olli Etuaho336b1472016-10-05 16:37:55 +0100877 visitCodeBlock(node->getBody());
Olli Etuaho336b1472016-10-05 16:37:55 +0100878
879 // Fully processed; no need to visit children.
880 return false;
881}
882
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000883bool TOutputGLSLBase::visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node)
884{
885 TInfoSinkBase &out = objSink();
886 ASSERT(visit == PreVisit);
887 const TIntermSymbol *symbol = node->getSymbol();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200888 out << "invariant " << hashName(&symbol->variable());
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000889 return false;
890}
891
Olli Etuahod4bd9632018-03-08 16:32:44 +0200892void TOutputGLSLBase::visitFunctionPrototype(TIntermFunctionPrototype *node)
Olli Etuaho16c745a2017-01-16 17:02:27 +0000893{
894 TInfoSinkBase &out = objSink();
Olli Etuaho16c745a2017-01-16 17:02:27 +0000895
896 const TType &type = node->getType();
Jamie Madillaed1b562018-04-17 11:47:46 -0400897 writeVariableType(type, node->getFunction());
Olli Etuaho16c745a2017-01-16 17:02:27 +0000898 if (type.isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300899 out << ArrayString(type);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000900
Olli Etuahobeb6dc72017-12-14 16:03:03 +0200901 out << " " << hashFunctionNameIfNeeded(node->getFunction());
Olli Etuaho16c745a2017-01-16 17:02:27 +0000902
903 out << "(";
Olli Etuahod4bd9632018-03-08 16:32:44 +0200904 writeFunctionParameters(node->getFunction());
Olli Etuaho16c745a2017-01-16 17:02:27 +0000905 out << ")";
Olli Etuaho16c745a2017-01-16 17:02:27 +0000906}
907
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700908bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000909{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500910 bool visitChildren = true;
911 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000912 switch (node->getOp())
913 {
Olli Etuaho1ecd14b2017-01-26 13:54:15 -0800914 case EOpCallFunctionInAST:
915 case EOpCallInternalRawFunction:
916 case EOpCallBuiltInFunction:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500917 // Function call.
918 if (visit == PreVisit)
Olli Etuahoec9232b2017-03-27 17:01:37 +0300919 {
920 if (node->getOp() == EOpCallBuiltInFunction)
921 {
Olli Etuahobed35d72017-12-20 16:36:26 +0200922 out << translateTextureFunction(node->getFunction()->name());
Olli Etuahoec9232b2017-03-27 17:01:37 +0300923 }
924 else
925 {
Olli Etuaho1bb85282017-12-14 13:39:53 +0200926 out << hashFunctionNameIfNeeded(node->getFunction());
Olli Etuahoec9232b2017-03-27 17:01:37 +0300927 }
928 out << "(";
929 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500930 else if (visit == InVisit)
931 out << ", ";
932 else
933 out << ")";
934 break;
Olli Etuaho8fab3202017-05-08 18:22:22 +0300935 case EOpConstruct:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500936 writeConstructorTriplet(visit, node->getType());
937 break;
Olli Etuahoe39706d2014-12-30 16:40:36 +0200938
Olli Etuahoe1805592017-01-02 16:41:20 +0000939 case EOpEqualComponentWise:
940 case EOpNotEqualComponentWise:
941 case EOpLessThanComponentWise:
942 case EOpGreaterThanComponentWise:
943 case EOpLessThanEqualComponentWise:
944 case EOpGreaterThanEqualComponentWise:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500945 case EOpMod:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500946 case EOpModf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500947 case EOpPow:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500948 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500949 case EOpMin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500950 case EOpMax:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500951 case EOpClamp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500952 case EOpMix:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500953 case EOpStep:
Olli Etuahof7f0b8c2018-02-21 20:02:23 +0200954 case EOpSmoothstep:
Olli Etuaho74da73f2017-02-01 15:37:48 +0000955 case EOpFrexp:
956 case EOpLdexp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500957 case EOpDistance:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500958 case EOpDot:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500959 case EOpCross:
Jamie Madille72595b2017-06-06 15:12:26 -0400960 case EOpFaceforward:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500961 case EOpReflect:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500962 case EOpRefract:
Olli Etuahoe1805592017-01-02 16:41:20 +0000963 case EOpMulMatrixComponentWise:
964 case EOpOuterProduct:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000965 case EOpBitfieldExtract:
966 case EOpBitfieldInsert:
967 case EOpUaddCarry:
968 case EOpUsubBorrow:
969 case EOpUmulExtended:
970 case EOpImulExtended:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300971 case EOpBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300972 case EOpMemoryBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300973 case EOpMemoryBarrierAtomicCounter:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300974 case EOpMemoryBarrierBuffer:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300975 case EOpMemoryBarrierImage:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300976 case EOpMemoryBarrierShared:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300977 case EOpGroupMemoryBarrier:
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800978 case EOpEmitVertex:
979 case EOpEndPrimitive:
Olli Etuahod68924e2017-01-02 17:34:40 +0000980 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300981 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500982 default:
983 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000984 }
zmo@google.com5601ea02011-06-10 18:23:25 +0000985 return visitChildren;
986}
987
Olli Etuaho13389b62016-10-16 11:48:18 +0100988bool TOutputGLSLBase::visitDeclaration(Visit visit, TIntermDeclaration *node)
989{
990 TInfoSinkBase &out = objSink();
991
992 // Variable declaration.
993 if (visit == PreVisit)
994 {
995 const TIntermSequence &sequence = *(node->getSequence());
Jamie Madill2a9e1072017-09-22 11:31:57 -0400996 TIntermTyped *variable = sequence.front()->getAsTyped();
997 writeLayoutQualifier(variable);
Jamie Madillc90d4d32018-04-17 13:11:15 -0400998 TIntermSymbol *symbolNode = variable->getAsSymbolNode();
999 writeVariableType(variable->getType(), symbolNode ? &symbolNode->variable() : nullptr);
Olli Etuaho39f74df2017-11-20 16:09:57 +02001000 if (variable->getAsSymbolNode() == nullptr ||
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001001 variable->getAsSymbolNode()->variable().symbolType() != SymbolType::Empty)
Olli Etuaho39f74df2017-11-20 16:09:57 +02001002 {
1003 out << " ";
1004 }
1005 mDeclaringVariable = true;
Olli Etuaho13389b62016-10-16 11:48:18 +01001006 }
1007 else if (visit == InVisit)
1008 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001009 UNREACHABLE();
Olli Etuaho13389b62016-10-16 11:48:18 +01001010 }
1011 else
1012 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001013 mDeclaringVariable = false;
Olli Etuaho13389b62016-10-16 11:48:18 +01001014 }
1015 return true;
1016}
1017
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001018bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001019{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001020 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +00001021
zmo@google.com5601ea02011-06-10 18:23:25 +00001022 TLoopType loopType = node->getType();
Corentin Wallez7258e302015-09-22 10:40:24 -07001023
zmo@google.com5601ea02011-06-10 18:23:25 +00001024 if (loopType == ELoopFor) // for loop
1025 {
Corentin Wallez1b896c62016-11-16 13:10:44 -05001026 out << "for (";
1027 if (node->getInit())
1028 node->getInit()->traverse(this);
1029 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001030
Corentin Wallez1b896c62016-11-16 13:10:44 -05001031 if (node->getCondition())
1032 node->getCondition()->traverse(this);
1033 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001034
Corentin Wallez1b896c62016-11-16 13:10:44 -05001035 if (node->getExpression())
1036 node->getExpression()->traverse(this);
1037 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001038
Corentin Wallez1b896c62016-11-16 13:10:44 -05001039 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001040 }
1041 else if (loopType == ELoopWhile) // while loop
1042 {
1043 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001044 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001045 node->getCondition()->traverse(this);
1046 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001047
1048 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001049 }
1050 else // do-while loop
1051 {
1052 ASSERT(loopType == ELoopDoWhile);
1053 out << "do\n";
zmo@google.com5601ea02011-06-10 18:23:25 +00001054
zmo@google.com5601ea02011-06-10 18:23:25 +00001055 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001056
zmo@google.com5601ea02011-06-10 18:23:25 +00001057 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001058 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001059 node->getCondition()->traverse(this);
1060 out << ");\n";
1061 }
Corentin Wallez7258e302015-09-22 10:40:24 -07001062
zmo@google.com5601ea02011-06-10 18:23:25 +00001063 // No need to visit children. They have been already processed in
1064 // this function.
1065 return false;
1066}
1067
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001068bool TOutputGLSLBase::visitBranch(Visit visit, TIntermBranch *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001069{
1070 switch (node->getFlowOp())
1071 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001072 case EOpKill:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001073 writeTriplet(visit, "discard", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001074 break;
1075 case EOpBreak:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001076 writeTriplet(visit, "break", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001077 break;
1078 case EOpContinue:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001079 writeTriplet(visit, "continue", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001080 break;
1081 case EOpReturn:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001082 writeTriplet(visit, "return ", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001083 break;
1084 default:
1085 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +00001086 }
1087
1088 return true;
1089}
1090
Olli Etuaho6d40bbd2016-09-30 13:49:38 +01001091void TOutputGLSLBase::visitCodeBlock(TIntermBlock *node)
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001092{
zmo@google.com5601ea02011-06-10 18:23:25 +00001093 TInfoSinkBase &out = objSink();
Yunchao He4f285442017-04-21 12:15:49 +08001094 if (node != nullptr)
zmo@google.com5601ea02011-06-10 18:23:25 +00001095 {
1096 node->traverse(this);
1097 // Single statements not part of a sequence need to be terminated
1098 // with semi-colon.
1099 if (isSingleStatement(node))
1100 out << ";\n";
1101 }
1102 else
1103 {
1104 out << "{\n}\n"; // Empty code block.
1105 }
1106}
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001107
Olli Etuahofbb1c792018-01-19 16:26:59 +02001108ImmutableString TOutputGLSLBase::getTypeName(const TType &type)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001109{
Jamie Madill6276b922017-09-25 02:35:57 -04001110 return GetTypeName(type, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001111}
1112
Olli Etuahofbb1c792018-01-19 16:26:59 +02001113ImmutableString TOutputGLSLBase::hashName(const TSymbol *symbol)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001114{
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001115 return HashName(symbol, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001116}
1117
Jamie Madillf5557ac2018-06-15 09:46:58 -04001118ImmutableString TOutputGLSLBase::hashFieldName(const TField *field)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001119{
Jamie Madillf5557ac2018-06-15 09:46:58 -04001120 ASSERT(field->symbolType() != SymbolType::Empty);
1121 if (field->symbolType() == SymbolType::UserDefined)
Olli Etuaho09b04a22016-12-15 13:30:26 +00001122 {
Jamie Madillf5557ac2018-06-15 09:46:58 -04001123 return HashName(field->name(), mHashFunction, &mNameMap);
Olli Etuaho09b04a22016-12-15 13:30:26 +00001124 }
Jamie Madillf5557ac2018-06-15 09:46:58 -04001125
1126 return field->name();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001127}
1128
Olli Etuahofbb1c792018-01-19 16:26:59 +02001129ImmutableString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunction *func)
Olli Etuaho1bb85282017-12-14 13:39:53 +02001130{
1131 if (func->isMain())
1132 {
Olli Etuahobed35d72017-12-20 16:36:26 +02001133 return func->name();
Olli Etuaho1bb85282017-12-14 13:39:53 +02001134 }
1135 else
1136 {
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001137 return hashName(func);
Olli Etuaho1bb85282017-12-14 13:39:53 +02001138 }
1139}
1140
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001141bool TOutputGLSLBase::structDeclared(const TStructure *structure) const
Jamie Madill98493dd2013-07-08 14:39:03 -04001142{
Zhenyao Mo904a9162014-05-09 14:07:45 -07001143 ASSERT(structure);
Olli Etuaho9d4d7f02017-12-07 17:11:41 +01001144 if (structure->symbolType() == SymbolType::Empty)
Zhenyao Mo904a9162014-05-09 14:07:45 -07001145 {
Jamie Madill01f85ac2014-06-06 11:55:04 -04001146 return false;
Zhenyao Mo904a9162014-05-09 14:07:45 -07001147 }
Jamie Madill01f85ac2014-06-06 11:55:04 -04001148
Olli Etuaho97fa8552017-11-28 16:28:42 +02001149 return (mDeclaredStructs.count(structure->uniqueId().get()) > 0);
Jamie Madill98493dd2013-07-08 14:39:03 -04001150}
1151
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001152void TOutputGLSLBase::declareStruct(const TStructure *structure)
Jamie Madill98493dd2013-07-08 14:39:03 -04001153{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001154 TInfoSinkBase &out = objSink();
Jamie Madill98493dd2013-07-08 14:39:03 -04001155
Olli Etuahobed35d72017-12-20 16:36:26 +02001156 out << "struct ";
1157
1158 if (structure->symbolType() != SymbolType::Empty)
1159 {
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001160 out << hashName(structure) << " ";
Olli Etuahobed35d72017-12-20 16:36:26 +02001161 }
1162 out << "{\n";
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001163 const TFieldList &fields = structure->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -04001164 for (size_t i = 0; i < fields.size(); ++i)
1165 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001166 const TField *field = fields[i];
Jamie Madill98493dd2013-07-08 14:39:03 -04001167 if (writeVariablePrecision(field->type()->getPrecision()))
1168 out << " ";
Jamie Madillf5557ac2018-06-15 09:46:58 -04001169 out << getTypeName(*field->type()) << " " << hashFieldName(field);
Jamie Madill98493dd2013-07-08 14:39:03 -04001170 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001171 out << ArrayString(*field->type());
Jamie Madill98493dd2013-07-08 14:39:03 -04001172 out << ";\n";
1173 }
1174 out << "}";
Luc Ferron3ec304d2018-04-18 14:14:25 -04001175
1176 if (structure->symbolType() != SymbolType::Empty)
1177 {
1178 mDeclaredStructs.insert(structure->uniqueId().get());
1179 }
Zhenyao Mo904a9162014-05-09 14:07:45 -07001180}
Jamie Madill98493dd2013-07-08 14:39:03 -04001181
Geoff Langbdcc54a2015-09-02 13:09:48 -04001182void TOutputGLSLBase::declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock)
1183{
1184 TInfoSinkBase &out = objSink();
1185
1186 out << "layout(";
1187
1188 switch (interfaceBlock->blockStorage())
1189 {
1190 case EbsUnspecified:
1191 case EbsShared:
1192 // Default block storage is shared.
1193 out << "shared";
1194 break;
1195
1196 case EbsPacked:
1197 out << "packed";
1198 break;
1199
1200 case EbsStd140:
1201 out << "std140";
1202 break;
1203
Qin Jiajiaca68d982017-09-18 16:41:56 +08001204 case EbsStd430:
1205 out << "std430";
1206 break;
1207
Geoff Langbdcc54a2015-09-02 13:09:48 -04001208 default:
1209 UNREACHABLE();
1210 break;
1211 }
1212
Jiajia Qinfeb2c632017-12-08 17:59:19 +08001213 if (interfaceBlock->blockBinding() >= 0)
Jiajia Qin729b2c62017-08-14 09:36:11 +08001214 {
Jiajia Qin729b2c62017-08-14 09:36:11 +08001215 out << ", ";
Olli Etuaho3de27032017-11-30 12:16:47 +02001216 out << "binding = " << interfaceBlock->blockBinding();
Geoff Langbdcc54a2015-09-02 13:09:48 -04001217 }
1218
1219 out << ") ";
1220}
1221
1222void TOutputGLSLBase::declareInterfaceBlock(const TInterfaceBlock *interfaceBlock)
1223{
1224 TInfoSinkBase &out = objSink();
1225
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001226 out << hashName(interfaceBlock) << "{\n";
Geoff Langbdcc54a2015-09-02 13:09:48 -04001227 const TFieldList &fields = interfaceBlock->fields();
Olli Etuaho3de27032017-11-30 12:16:47 +02001228 for (const TField *field : fields)
Geoff Langbdcc54a2015-09-02 13:09:48 -04001229 {
Olli Etuaho3de27032017-11-30 12:16:47 +02001230 if (field->type()->isMatrix() || field->type()->isStructureContainingMatrices())
1231 {
1232 out << "layout(";
1233 switch (field->type()->getLayoutQualifier().matrixPacking)
1234 {
1235 case EmpUnspecified:
1236 case EmpColumnMajor:
1237 // Default matrix packing is column major.
1238 out << "column_major";
1239 break;
1240
1241 case EmpRowMajor:
1242 out << "row_major";
1243 break;
1244
1245 default:
1246 UNREACHABLE();
1247 break;
1248 }
1249 out << ") ";
1250 }
1251
Geoff Langbdcc54a2015-09-02 13:09:48 -04001252 if (writeVariablePrecision(field->type()->getPrecision()))
1253 out << " ";
Jamie Madillf5557ac2018-06-15 09:46:58 -04001254 out << getTypeName(*field->type()) << " " << hashFieldName(field);
Geoff Langbdcc54a2015-09-02 13:09:48 -04001255 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001256 out << ArrayString(*field->type());
Geoff Langbdcc54a2015-09-02 13:09:48 -04001257 out << ";\n";
1258 }
1259 out << "}";
1260}
Jamie Madill45bcc782016-11-07 13:58:48 -05001261
Shaob5cc1192017-07-06 10:47:20 +08001262void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out,
1263 sh::TLayoutPrimitiveType inputPrimitive,
1264 int invocations,
1265 sh::TLayoutPrimitiveType outputPrimitive,
1266 int maxVertices)
1267{
1268 // Omit 'invocations = 1'
1269 if (inputPrimitive != EptUndefined || invocations > 1)
1270 {
1271 out << "layout (";
1272
1273 if (inputPrimitive != EptUndefined)
1274 {
1275 out << getGeometryShaderPrimitiveTypeString(inputPrimitive);
1276 }
1277
1278 if (invocations > 1)
1279 {
1280 if (inputPrimitive != EptUndefined)
1281 {
1282 out << ", ";
1283 }
1284 out << "invocations = " << invocations;
1285 }
1286 out << ") in;\n";
1287 }
1288
1289 if (outputPrimitive != EptUndefined || maxVertices != -1)
1290 {
1291 out << "layout (";
1292
1293 if (outputPrimitive != EptUndefined)
1294 {
1295 out << getGeometryShaderPrimitiveTypeString(outputPrimitive);
1296 }
1297
1298 if (maxVertices != -1)
1299 {
1300 if (outputPrimitive != EptUndefined)
1301 {
1302 out << ", ";
1303 }
1304 out << "max_vertices = " << maxVertices;
1305 }
1306 out << ") out;\n";
1307 }
1308}
1309
Jamie Madill2a9e1072017-09-22 11:31:57 -04001310// If SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS is enabled, layout qualifiers are spilled whenever
1311// variables with specified layout qualifiers are copied. Additional checks are needed against the
1312// type and storage qualifier of the variable to verify that layout qualifiers have to be outputted.
1313// TODO (mradev): Fix layout qualifier spilling in ScalarizeVecAndMatConstructorArgs and remove
1314// NeedsToWriteLayoutQualifier.
1315bool NeedsToWriteLayoutQualifier(const TType &type)
1316{
1317 if (type.getBasicType() == EbtInterfaceBlock)
1318 {
1319 return false;
1320 }
1321
1322 const TLayoutQualifier &layoutQualifier = type.getLayoutQualifier();
1323
1324 if ((type.getQualifier() == EvqFragmentOut || type.getQualifier() == EvqVertexIn ||
1325 IsVarying(type.getQualifier())) &&
1326 layoutQualifier.location >= 0)
1327 {
1328 return true;
1329 }
1330
1331 if (type.getQualifier() == EvqFragmentOut && layoutQualifier.yuv == true)
1332 {
1333 return true;
1334 }
1335
1336 if (IsOpaqueType(type.getBasicType()) && layoutQualifier.binding != -1)
1337 {
1338 return true;
1339 }
1340
1341 if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified)
1342 {
1343 return true;
1344 }
1345 return false;
1346}
1347
Jamie Madill45bcc782016-11-07 13:58:48 -05001348} // namespace sh