blob: 2e1926490add17d4a70c8fe9aa88678d792a8f8b [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
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800217const char *TOutputGLSLBase::mapQualifierToString(TQualifier qualifier)
218{
219 if (sh::IsGLSL410OrOlder(mOutput) && mShaderVersion >= 300 &&
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000220 (mCompileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0)
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800221 {
222 switch (qualifier)
223 {
224 // The return string is consistent with sh::getQualifierString() from
225 // BaseTypes.h minus the "centroid" keyword.
226 case EvqCentroid:
227 return "";
228 case EvqCentroidIn:
229 return "smooth in";
230 case EvqCentroidOut:
231 return "smooth out";
232 default:
233 break;
234 }
235 }
236 if (sh::IsGLSL130OrNewer(mOutput))
237 {
238 switch (qualifier)
239 {
240 case EvqAttribute:
241 return "in";
242 case EvqVaryingIn:
243 return "in";
244 case EvqVaryingOut:
245 return "out";
246 default:
247 break;
248 }
249 }
250 return sh::getQualifierString(qualifier);
251}
252
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700253void TOutputGLSLBase::writeVariableType(const TType &type)
254{
Qiankun Miao705a9192016-08-29 10:05:27 +0800255 TQualifier qualifier = type.getQualifier();
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500256 TInfoSinkBase &out = objSink();
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800257 if (type.isInvariant())
Olli Etuaho214c2d82015-04-27 14:49:13 +0300258 {
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800259 writeInvariantQualifier(type);
Olli Etuaho214c2d82015-04-27 14:49:13 +0300260 }
Geoff Langbdcc54a2015-09-02 13:09:48 -0400261 if (type.getBasicType() == EbtInterfaceBlock)
262 {
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200263 const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
Geoff Langbdcc54a2015-09-02 13:09:48 -0400264 declareInterfaceBlockLayout(interfaceBlock);
265 }
Jamie Madill3b5c2da2014-08-19 15:23:32 -0400266 if (qualifier != EvqTemporary && qualifier != EvqGlobal)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400267 {
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800268 const char *qualifierString = mapQualifierToString(qualifier);
269 if (qualifierString && qualifierString[0] != '\0')
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -0800270 {
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800271 out << qualifierString << " ";
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -0800272 }
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400273 }
Martin Radev2cc85b32016-08-05 16:22:53 +0300274
275 const TMemoryQualifier &memoryQualifier = type.getMemoryQualifier();
276 if (memoryQualifier.readonly)
277 {
278 ASSERT(IsImage(type.getBasicType()));
279 out << "readonly ";
280 }
281
282 if (memoryQualifier.writeonly)
283 {
284 ASSERT(IsImage(type.getBasicType()));
285 out << "writeonly ";
286 }
287
Martin Radev049edfa2016-11-11 14:35:37 +0200288 if (memoryQualifier.coherent)
289 {
290 ASSERT(IsImage(type.getBasicType()));
291 out << "coherent ";
292 }
293
294 if (memoryQualifier.restrictQualifier)
295 {
296 ASSERT(IsImage(type.getBasicType()));
297 out << "restrict ";
298 }
299
300 if (memoryQualifier.volatileQualifier)
301 {
302 ASSERT(IsImage(type.getBasicType()));
303 out << "volatile ";
304 }
305
zmo@google.com5601ea02011-06-10 18:23:25 +0000306 // Declare the struct if we have not done so already.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700307 if (type.getBasicType() == EbtStruct && !structDeclared(type.getStruct()))
zmo@google.com5601ea02011-06-10 18:23:25 +0000308 {
Olli Etuahobd3cd502017-11-03 15:48:52 +0200309 const TStructure *structure = type.getStruct();
Jamie Madill01f85ac2014-06-06 11:55:04 -0400310
311 declareStruct(structure);
312
Olli Etuaho9d4d7f02017-12-07 17:11:41 +0100313 if (structure->symbolType() != SymbolType::Empty)
Jamie Madill01f85ac2014-06-06 11:55:04 -0400314 {
Olli Etuaho97fa8552017-11-28 16:28:42 +0200315 mDeclaredStructs.insert(structure->uniqueId().get());
Jamie Madill01f85ac2014-06-06 11:55:04 -0400316 }
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
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700331void TOutputGLSLBase::writeFunctionParameters(const TIntermSequence &args)
zmo@google.com5601ea02011-06-10 18:23:25 +0000332{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700333 TInfoSinkBase &out = objSink();
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500334 for (TIntermSequence::const_iterator iter = args.begin(); iter != args.end(); ++iter)
zmo@google.com5601ea02011-06-10 18:23:25 +0000335 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700336 const TIntermSymbol *arg = (*iter)->getAsSymbolNode();
Yunchao He4f285442017-04-21 12:15:49 +0800337 ASSERT(arg != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +0000338
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700339 const TType &type = arg->getType();
zmo@google.com189be2f2011-06-16 18:28:53 +0000340 writeVariableType(type);
zmo@google.com5601ea02011-06-10 18:23:25 +0000341
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200342 if (arg->variable().symbolType() != SymbolType::Empty)
343 out << " " << hashName(&arg->variable());
zmo@google.com5601ea02011-06-10 18:23:25 +0000344 if (type.isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300345 out << ArrayString(type);
zmo@google.com5601ea02011-06-10 18:23:25 +0000346
347 // Put a comma if this is not the last argument.
348 if (iter != args.end() - 1)
349 out << ", ";
350 }
351}
352
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500353const TConstantUnion *TOutputGLSLBase::writeConstantUnion(const TType &type,
354 const TConstantUnion *pConstUnion)
zmo@google.com5601ea02011-06-10 18:23:25 +0000355{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700356 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000357
358 if (type.getBasicType() == EbtStruct)
359 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700360 const TStructure *structure = type.getStruct();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200361 out << hashName(structure) << "(";
Jamie Madill98493dd2013-07-08 14:39:03 -0400362
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700363 const TFieldList &fields = structure->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -0400364 for (size_t i = 0; i < fields.size(); ++i)
zmo@google.com5601ea02011-06-10 18:23:25 +0000365 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700366 const TType *fieldType = fields[i]->type();
Yunchao He4f285442017-04-21 12:15:49 +0800367 ASSERT(fieldType != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +0000368 pConstUnion = writeConstantUnion(*fieldType, pConstUnion);
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700369 if (i != fields.size() - 1)
370 out << ", ";
zmo@google.com5601ea02011-06-10 18:23:25 +0000371 }
372 out << ")";
373 }
374 else
375 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500376 size_t size = type.getObjectSize();
zmo@google.com5601ea02011-06-10 18:23:25 +0000377 bool writeType = size > 1;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700378 if (writeType)
379 out << getTypeName(type) << "(";
Jamie Madill94bf7f22013-07-08 13:31:15 -0400380 for (size_t i = 0; i < size; ++i, ++pConstUnion)
zmo@google.com5601ea02011-06-10 18:23:25 +0000381 {
382 switch (pConstUnion->getType())
383 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500384 case EbtFloat:
385 writeFloat(out, pConstUnion->getFConst());
386 break;
387 case EbtInt:
388 out << pConstUnion->getIConst();
389 break;
390 case EbtUInt:
391 out << pConstUnion->getUConst() << "u";
392 break;
393 case EbtBool:
394 out << pConstUnion->getBConst();
395 break;
Andrei Volykhina5527072017-03-22 16:46:30 +0300396 case EbtYuvCscStandardEXT:
397 out << getYuvCscStandardEXTString(pConstUnion->getYuvCscStandardEXTConst());
398 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500399 default:
400 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000401 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700402 if (i != size - 1)
403 out << ", ";
zmo@google.com5601ea02011-06-10 18:23:25 +0000404 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700405 if (writeType)
406 out << ")";
zmo@google.com5601ea02011-06-10 18:23:25 +0000407 }
408 return pConstUnion;
409}
410
Olli Etuahoe92507b2016-07-04 11:20:10 +0300411void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type)
Olli Etuahof40319e2015-03-10 14:33:00 +0200412{
413 TInfoSinkBase &out = objSink();
414 if (visit == PreVisit)
415 {
416 if (type.isArray())
417 {
Olli Etuahoe92507b2016-07-04 11:20:10 +0300418 out << getTypeName(type);
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300419 out << ArrayString(type);
Olli Etuahof40319e2015-03-10 14:33:00 +0200420 out << "(";
421 }
422 else
423 {
Olli Etuahoe92507b2016-07-04 11:20:10 +0300424 out << getTypeName(type) << "(";
Olli Etuahof40319e2015-03-10 14:33:00 +0200425 }
426 }
427 else
428 {
429 writeTriplet(visit, nullptr, ", ", ")");
430 }
431}
432
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700433void TOutputGLSLBase::visitSymbol(TIntermSymbol *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000434{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700435 TInfoSinkBase &out = objSink();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200436 out << hashName(&node->variable());
zmo@google.com5601ea02011-06-10 18:23:25 +0000437
Olli Etuaho39f74df2017-11-20 16:09:57 +0200438 if (mDeclaringVariable && node->getType().isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300439 out << ArrayString(node->getType());
zmo@google.com5601ea02011-06-10 18:23:25 +0000440}
441
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700442void TOutputGLSLBase::visitConstantUnion(TIntermConstantUnion *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000443{
Olli Etuahoea22b7a2018-01-04 17:09:11 +0200444 writeConstantUnion(node->getType(), node->getConstantValue());
zmo@google.com5601ea02011-06-10 18:23:25 +0000445}
446
Olli Etuahob6fa0432016-09-28 16:28:05 +0100447bool TOutputGLSLBase::visitSwizzle(Visit visit, TIntermSwizzle *node)
448{
449 TInfoSinkBase &out = objSink();
450 if (visit == PostVisit)
451 {
452 out << ".";
453 node->writeOffsetsAsXYZW(&out);
454 }
455 return true;
456}
457
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700458bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000459{
460 bool visitChildren = true;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700461 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000462 switch (node->getOp())
463 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100464 case EOpComma:
465 writeTriplet(visit, "(", ", ", ")");
466 break;
467 case EOpInitialize:
zmo@google.com5601ea02011-06-10 18:23:25 +0000468 if (visit == InVisit)
469 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100470 out << " = ";
471 // RHS of initialize is not being declared.
Olli Etuaho39f74df2017-11-20 16:09:57 +0200472 mDeclaringVariable = false;
zmo@google.com5601ea02011-06-10 18:23:25 +0000473 }
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100474 break;
475 case EOpAssign:
476 writeTriplet(visit, "(", " = ", ")");
477 break;
478 case EOpAddAssign:
479 writeTriplet(visit, "(", " += ", ")");
480 break;
481 case EOpSubAssign:
482 writeTriplet(visit, "(", " -= ", ")");
483 break;
484 case EOpDivAssign:
485 writeTriplet(visit, "(", " /= ", ")");
486 break;
487 case EOpIModAssign:
488 writeTriplet(visit, "(", " %= ", ")");
489 break;
490 // Notice the fall-through.
491 case EOpMulAssign:
492 case EOpVectorTimesMatrixAssign:
493 case EOpVectorTimesScalarAssign:
494 case EOpMatrixTimesScalarAssign:
495 case EOpMatrixTimesMatrixAssign:
496 writeTriplet(visit, "(", " *= ", ")");
497 break;
498 case EOpBitShiftLeftAssign:
499 writeTriplet(visit, "(", " <<= ", ")");
500 break;
501 case EOpBitShiftRightAssign:
502 writeTriplet(visit, "(", " >>= ", ")");
503 break;
504 case EOpBitwiseAndAssign:
505 writeTriplet(visit, "(", " &= ", ")");
506 break;
507 case EOpBitwiseXorAssign:
508 writeTriplet(visit, "(", " ^= ", ")");
509 break;
510 case EOpBitwiseOrAssign:
511 writeTriplet(visit, "(", " |= ", ")");
512 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000513
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100514 case EOpIndexDirect:
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800515 writeTriplet(visit, nullptr, "[", "]");
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100516 break;
517 case EOpIndexIndirect:
518 if (node->getAddIndexClamp())
519 {
520 if (visit == InVisit)
521 {
522 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
523 out << "[int(clamp(float(";
524 else
525 out << "[webgl_int_clamp(";
526 }
527 else if (visit == PostVisit)
528 {
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100529 TIntermTyped *left = node->getLeft();
530 TType leftType = left->getType();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700531
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100532 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
Olli Etuahoebee5b32017-11-23 12:56:32 +0200533 out << "), 0.0, float(";
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100534 else
Olli Etuahoebee5b32017-11-23 12:56:32 +0200535 out << ", 0, ";
536
537 if (leftType.isUnsizedArray())
538 {
539 // For runtime-sized arrays in ESSL 3.10 we need to call the length method
540 // to get the length to clamp against. See ESSL 3.10 section 4.1.9. Note
541 // that a runtime-sized array expression is guaranteed not to have side
542 // effects, so it's fine to add the expression to the output twice.
543 ASSERT(mShaderVersion >= 310);
544 ASSERT(!left->hasSideEffects());
545 left->traverse(this);
546 out << ".length() - 1";
547 }
548 else
549 {
550 int maxSize;
551 if (leftType.isArray())
552 {
553 maxSize = static_cast<int>(leftType.getOutermostArraySize()) - 1;
554 }
555 else
556 {
557 maxSize = leftType.getNominalSize() - 1;
558 }
559 out << maxSize;
560 }
561 if (mClampingStrategy == SH_CLAMP_WITH_CLAMP_INTRINSIC)
562 out << ")))]";
563 else
564 out << ")]";
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100565 }
566 }
567 else
568 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800569 writeTriplet(visit, nullptr, "[", "]");
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100570 }
571 break;
572 case EOpIndexDirectStruct:
573 if (visit == InVisit)
574 {
575 // Here we are writing out "foo.bar", where "foo" is struct
576 // and "bar" is field. In AST, it is represented as a binary
577 // node, where left child represents "foo" and right child "bar".
578 // The node itself represents ".". The struct field "bar" is
579 // actually stored as an index into TStructure::fields.
580 out << ".";
581 const TStructure *structure = node->getLeft()->getType().getStruct();
582 const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
583 const TField *field = structure->fields()[index->getIConst(0)];
584
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200585 out << hashFieldName(structure, field->name());
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100586 visitChildren = false;
587 }
588 break;
589 case EOpIndexDirectInterfaceBlock:
590 if (visit == InVisit)
591 {
592 out << ".";
593 const TInterfaceBlock *interfaceBlock =
594 node->getLeft()->getType().getInterfaceBlock();
595 const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
596 const TField *field = interfaceBlock->fields()[index->getIConst(0)];
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200597 ASSERT(interfaceBlock->symbolType() == SymbolType::UserDefined ||
598 interfaceBlock->name() == "gl_PerVertex");
599 out << hashFieldName(interfaceBlock, field->name());
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100600 visitChildren = false;
601 }
602 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400603
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100604 case EOpAdd:
605 writeTriplet(visit, "(", " + ", ")");
606 break;
607 case EOpSub:
608 writeTriplet(visit, "(", " - ", ")");
609 break;
610 case EOpMul:
611 writeTriplet(visit, "(", " * ", ")");
612 break;
613 case EOpDiv:
614 writeTriplet(visit, "(", " / ", ")");
615 break;
616 case EOpIMod:
617 writeTriplet(visit, "(", " % ", ")");
618 break;
619 case EOpBitShiftLeft:
620 writeTriplet(visit, "(", " << ", ")");
621 break;
622 case EOpBitShiftRight:
623 writeTriplet(visit, "(", " >> ", ")");
624 break;
625 case EOpBitwiseAnd:
626 writeTriplet(visit, "(", " & ", ")");
627 break;
628 case EOpBitwiseXor:
629 writeTriplet(visit, "(", " ^ ", ")");
630 break;
631 case EOpBitwiseOr:
632 writeTriplet(visit, "(", " | ", ")");
633 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400634
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100635 case EOpEqual:
636 writeTriplet(visit, "(", " == ", ")");
637 break;
638 case EOpNotEqual:
639 writeTriplet(visit, "(", " != ", ")");
640 break;
641 case EOpLessThan:
642 writeTriplet(visit, "(", " < ", ")");
643 break;
644 case EOpGreaterThan:
645 writeTriplet(visit, "(", " > ", ")");
646 break;
647 case EOpLessThanEqual:
648 writeTriplet(visit, "(", " <= ", ")");
649 break;
650 case EOpGreaterThanEqual:
651 writeTriplet(visit, "(", " >= ", ")");
652 break;
daniel@transgaming.com97b16d12013-02-01 03:20:42 +0000653
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100654 // Notice the fall-through.
655 case EOpVectorTimesScalar:
656 case EOpVectorTimesMatrix:
657 case EOpMatrixTimesVector:
658 case EOpMatrixTimesScalar:
659 case EOpMatrixTimesMatrix:
660 writeTriplet(visit, "(", " * ", ")");
661 break;
Olli Etuaho31b5fc62015-01-16 12:13:36 +0200662
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100663 case EOpLogicalOr:
664 writeTriplet(visit, "(", " || ", ")");
665 break;
666 case EOpLogicalXor:
667 writeTriplet(visit, "(", " ^^ ", ")");
668 break;
669 case EOpLogicalAnd:
670 writeTriplet(visit, "(", " && ", ")");
671 break;
672 default:
673 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000674 }
675
676 return visitChildren;
677}
678
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700679bool TOutputGLSLBase::visitUnary(Visit visit, TIntermUnary *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000680{
zmo@google.com32e97312011-08-24 01:03:11 +0000681 TString preString;
682 TString postString = ")";
683
zmo@google.com5601ea02011-06-10 18:23:25 +0000684 switch (node->getOp())
685 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500686 case EOpNegative:
687 preString = "(-";
688 break;
689 case EOpPositive:
690 preString = "(+";
691 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500692 case EOpLogicalNot:
693 preString = "(!";
694 break;
695 case EOpBitwiseNot:
696 preString = "(~";
697 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000698
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500699 case EOpPostIncrement:
700 preString = "(";
701 postString = "++)";
702 break;
703 case EOpPostDecrement:
704 preString = "(";
705 postString = "--)";
706 break;
707 case EOpPreIncrement:
708 preString = "(++";
709 break;
710 case EOpPreDecrement:
711 preString = "(--";
712 break;
Olli Etuahobb5a7e22017-08-30 13:03:12 +0300713 case EOpArrayLength:
714 preString = "((";
715 postString = ").length())";
716 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000717
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500718 case EOpRadians:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500719 case EOpDegrees:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500720 case EOpSin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500721 case EOpCos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500722 case EOpTan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500723 case EOpAsin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500724 case EOpAcos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500725 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500726 case EOpSinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500727 case EOpCosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500728 case EOpTanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500729 case EOpAsinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500730 case EOpAcosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500731 case EOpAtanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500732 case EOpExp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500733 case EOpLog:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500734 case EOpExp2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500735 case EOpLog2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500736 case EOpSqrt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500737 case EOpInverseSqrt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500738 case EOpAbs:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500739 case EOpSign:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500740 case EOpFloor:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500741 case EOpTrunc:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500742 case EOpRound:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500743 case EOpRoundEven:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500744 case EOpCeil:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500745 case EOpFract:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500746 case EOpIsNan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500747 case EOpIsInf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500748 case EOpFloatBitsToInt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500749 case EOpFloatBitsToUint:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500750 case EOpIntBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500751 case EOpUintBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500752 case EOpPackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500753 case EOpPackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500754 case EOpPackHalf2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500755 case EOpUnpackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500756 case EOpUnpackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500757 case EOpUnpackHalf2x16:
Olli Etuaho25aef452017-01-29 16:15:44 -0800758 case EOpPackUnorm4x8:
759 case EOpPackSnorm4x8:
760 case EOpUnpackUnorm4x8:
761 case EOpUnpackSnorm4x8:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500762 case EOpLength:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500763 case EOpNormalize:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500764 case EOpDFdx:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500765 case EOpDFdy:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500766 case EOpFwidth:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500767 case EOpTranspose:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500768 case EOpDeterminant:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500769 case EOpInverse:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500770 case EOpAny:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500771 case EOpAll:
Olli Etuahod68924e2017-01-02 17:34:40 +0000772 case EOpLogicalNotComponentWise:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000773 case EOpBitfieldReverse:
774 case EOpBitCount:
775 case EOpFindLSB:
776 case EOpFindMSB:
Olli Etuahod68924e2017-01-02 17:34:40 +0000777 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
778 return true;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500779 default:
780 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000781 }
782
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800783 writeTriplet(visit, preString.c_str(), nullptr, postString.c_str());
zmo@google.com32e97312011-08-24 01:03:11 +0000784
zmo@google.com5601ea02011-06-10 18:23:25 +0000785 return true;
786}
787
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300788bool TOutputGLSLBase::visitTernary(Visit visit, TIntermTernary *node)
789{
790 TInfoSinkBase &out = objSink();
791 // Notice two brackets at the beginning and end. The outer ones
792 // encapsulate the whole ternary expression. This preserves the
793 // order of precedence when ternary expressions are used in a
794 // compound expression, i.e., c = 2 * (a < b ? 1 : 2).
795 out << "((";
796 node->getCondition()->traverse(this);
797 out << ") ? (";
798 node->getTrueExpression()->traverse(this);
799 out << ") : (";
800 node->getFalseExpression()->traverse(this);
801 out << "))";
802 return false;
803}
804
Olli Etuaho57961272016-09-14 13:57:46 +0300805bool TOutputGLSLBase::visitIfElse(Visit visit, TIntermIfElse *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000806{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700807 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000808
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300809 out << "if (";
810 node->getCondition()->traverse(this);
811 out << ")\n";
zmo@google.com5601ea02011-06-10 18:23:25 +0000812
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300813 visitCodeBlock(node->getTrueBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000814
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300815 if (node->getFalseBlock())
816 {
817 out << "else\n";
818 visitCodeBlock(node->getFalseBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000819 }
820 return false;
821}
822
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200823bool TOutputGLSLBase::visitSwitch(Visit visit, TIntermSwitch *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200824{
Olli Etuaho923ecef2017-10-11 12:01:38 +0300825 ASSERT(node->getStatementList());
826 writeTriplet(visit, "switch (", ") ", nullptr);
827 // The curly braces get written when visiting the statementList aggregate
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200828 return true;
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200829}
830
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200831bool TOutputGLSLBase::visitCase(Visit visit, TIntermCase *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200832{
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200833 if (node->hasCondition())
834 {
835 writeTriplet(visit, "case (", nullptr, "):\n");
836 return true;
837 }
838 else
839 {
840 TInfoSinkBase &out = objSink();
841 out << "default:\n";
842 return false;
843 }
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200844}
845
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100846bool TOutputGLSLBase::visitBlock(Visit visit, TIntermBlock *node)
847{
848 TInfoSinkBase &out = objSink();
849 // Scope the blocks except when at the global scope.
850 if (mDepth > 0)
851 {
852 out << "{\n";
853 }
854
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100855 for (TIntermSequence::const_iterator iter = node->getSequence()->begin();
856 iter != node->getSequence()->end(); ++iter)
857 {
858 TIntermNode *curNode = *iter;
859 ASSERT(curNode != nullptr);
860 curNode->traverse(this);
861
862 if (isSingleStatement(curNode))
863 out << ";\n";
864 }
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100865
866 // Scope the blocks except when at the global scope.
867 if (mDepth > 0)
868 {
869 out << "}\n";
870 }
871 return false;
872}
873
Olli Etuaho336b1472016-10-05 16:37:55 +0100874bool TOutputGLSLBase::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
875{
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000876 TIntermFunctionPrototype *prototype = node->getFunctionPrototype();
877 prototype->traverse(this);
Olli Etuaho336b1472016-10-05 16:37:55 +0100878 visitCodeBlock(node->getBody());
Olli Etuaho336b1472016-10-05 16:37:55 +0100879
880 // Fully processed; no need to visit children.
881 return false;
882}
883
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000884bool TOutputGLSLBase::visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node)
885{
886 TInfoSinkBase &out = objSink();
887 ASSERT(visit == PreVisit);
888 const TIntermSymbol *symbol = node->getSymbol();
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +0200889 out << "invariant " << hashName(&symbol->variable());
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000890 return false;
891}
892
Olli Etuaho16c745a2017-01-16 17:02:27 +0000893bool TOutputGLSLBase::visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node)
894{
895 TInfoSinkBase &out = objSink();
896 ASSERT(visit == PreVisit);
897
898 const TType &type = node->getType();
899 writeVariableType(type);
900 if (type.isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300901 out << ArrayString(type);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000902
Olli Etuahobeb6dc72017-12-14 16:03:03 +0200903 out << " " << hashFunctionNameIfNeeded(node->getFunction());
Olli Etuaho16c745a2017-01-16 17:02:27 +0000904
905 out << "(";
906 writeFunctionParameters(*(node->getSequence()));
907 out << ")";
908
909 return false;
910}
911
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700912bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000913{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500914 bool visitChildren = true;
915 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000916 switch (node->getOp())
917 {
Olli Etuaho1ecd14b2017-01-26 13:54:15 -0800918 case EOpCallFunctionInAST:
919 case EOpCallInternalRawFunction:
920 case EOpCallBuiltInFunction:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500921 // Function call.
922 if (visit == PreVisit)
Olli Etuahoec9232b2017-03-27 17:01:37 +0300923 {
924 if (node->getOp() == EOpCallBuiltInFunction)
925 {
Olli Etuahobed35d72017-12-20 16:36:26 +0200926 out << translateTextureFunction(node->getFunction()->name());
Olli Etuahoec9232b2017-03-27 17:01:37 +0300927 }
928 else
929 {
Olli Etuaho1bb85282017-12-14 13:39:53 +0200930 out << hashFunctionNameIfNeeded(node->getFunction());
Olli Etuahoec9232b2017-03-27 17:01:37 +0300931 }
932 out << "(";
933 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500934 else if (visit == InVisit)
935 out << ", ";
936 else
937 out << ")";
938 break;
Olli Etuaho8fab3202017-05-08 18:22:22 +0300939 case EOpConstruct:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500940 writeConstructorTriplet(visit, node->getType());
941 break;
Olli Etuahoe39706d2014-12-30 16:40:36 +0200942
Olli Etuahoe1805592017-01-02 16:41:20 +0000943 case EOpEqualComponentWise:
944 case EOpNotEqualComponentWise:
945 case EOpLessThanComponentWise:
946 case EOpGreaterThanComponentWise:
947 case EOpLessThanEqualComponentWise:
948 case EOpGreaterThanEqualComponentWise:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500949 case EOpMod:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500950 case EOpModf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500951 case EOpPow:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500952 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500953 case EOpMin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500954 case EOpMax:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500955 case EOpClamp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500956 case EOpMix:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500957 case EOpStep:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500958 case EOpSmoothStep:
Olli Etuaho74da73f2017-02-01 15:37:48 +0000959 case EOpFrexp:
960 case EOpLdexp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500961 case EOpDistance:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500962 case EOpDot:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500963 case EOpCross:
Jamie Madille72595b2017-06-06 15:12:26 -0400964 case EOpFaceforward:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500965 case EOpReflect:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500966 case EOpRefract:
Olli Etuahoe1805592017-01-02 16:41:20 +0000967 case EOpMulMatrixComponentWise:
968 case EOpOuterProduct:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000969 case EOpBitfieldExtract:
970 case EOpBitfieldInsert:
971 case EOpUaddCarry:
972 case EOpUsubBorrow:
973 case EOpUmulExtended:
974 case EOpImulExtended:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300975 case EOpBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300976 case EOpMemoryBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300977 case EOpMemoryBarrierAtomicCounter:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300978 case EOpMemoryBarrierBuffer:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300979 case EOpMemoryBarrierImage:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300980 case EOpMemoryBarrierShared:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300981 case EOpGroupMemoryBarrier:
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800982 case EOpEmitVertex:
983 case EOpEndPrimitive:
Olli Etuahod68924e2017-01-02 17:34:40 +0000984 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300985 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500986 default:
987 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000988 }
zmo@google.com5601ea02011-06-10 18:23:25 +0000989 return visitChildren;
990}
991
Olli Etuaho13389b62016-10-16 11:48:18 +0100992bool TOutputGLSLBase::visitDeclaration(Visit visit, TIntermDeclaration *node)
993{
994 TInfoSinkBase &out = objSink();
995
996 // Variable declaration.
997 if (visit == PreVisit)
998 {
999 const TIntermSequence &sequence = *(node->getSequence());
Jamie Madill2a9e1072017-09-22 11:31:57 -04001000 TIntermTyped *variable = sequence.front()->getAsTyped();
1001 writeLayoutQualifier(variable);
Olli Etuaho13389b62016-10-16 11:48:18 +01001002 writeVariableType(variable->getType());
Olli Etuaho39f74df2017-11-20 16:09:57 +02001003 if (variable->getAsSymbolNode() == nullptr ||
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001004 variable->getAsSymbolNode()->variable().symbolType() != SymbolType::Empty)
Olli Etuaho39f74df2017-11-20 16:09:57 +02001005 {
1006 out << " ";
1007 }
1008 mDeclaringVariable = true;
Olli Etuaho13389b62016-10-16 11:48:18 +01001009 }
1010 else if (visit == InVisit)
1011 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001012 UNREACHABLE();
Olli Etuaho13389b62016-10-16 11:48:18 +01001013 }
1014 else
1015 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001016 mDeclaringVariable = false;
Olli Etuaho13389b62016-10-16 11:48:18 +01001017 }
1018 return true;
1019}
1020
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001021bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001022{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001023 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +00001024
zmo@google.com5601ea02011-06-10 18:23:25 +00001025 TLoopType loopType = node->getType();
Corentin Wallez7258e302015-09-22 10:40:24 -07001026
zmo@google.com5601ea02011-06-10 18:23:25 +00001027 if (loopType == ELoopFor) // for loop
1028 {
Corentin Wallez1b896c62016-11-16 13:10:44 -05001029 out << "for (";
1030 if (node->getInit())
1031 node->getInit()->traverse(this);
1032 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001033
Corentin Wallez1b896c62016-11-16 13:10:44 -05001034 if (node->getCondition())
1035 node->getCondition()->traverse(this);
1036 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001037
Corentin Wallez1b896c62016-11-16 13:10:44 -05001038 if (node->getExpression())
1039 node->getExpression()->traverse(this);
1040 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001041
Corentin Wallez1b896c62016-11-16 13:10:44 -05001042 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001043 }
1044 else if (loopType == ELoopWhile) // while loop
1045 {
1046 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001047 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001048 node->getCondition()->traverse(this);
1049 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001050
1051 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001052 }
1053 else // do-while loop
1054 {
1055 ASSERT(loopType == ELoopDoWhile);
1056 out << "do\n";
zmo@google.com5601ea02011-06-10 18:23:25 +00001057
zmo@google.com5601ea02011-06-10 18:23:25 +00001058 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001059
zmo@google.com5601ea02011-06-10 18:23:25 +00001060 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001061 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001062 node->getCondition()->traverse(this);
1063 out << ");\n";
1064 }
Corentin Wallez7258e302015-09-22 10:40:24 -07001065
zmo@google.com5601ea02011-06-10 18:23:25 +00001066 // No need to visit children. They have been already processed in
1067 // this function.
1068 return false;
1069}
1070
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001071bool TOutputGLSLBase::visitBranch(Visit visit, TIntermBranch *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001072{
1073 switch (node->getFlowOp())
1074 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001075 case EOpKill:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001076 writeTriplet(visit, "discard", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001077 break;
1078 case EOpBreak:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001079 writeTriplet(visit, "break", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001080 break;
1081 case EOpContinue:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001082 writeTriplet(visit, "continue", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001083 break;
1084 case EOpReturn:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001085 writeTriplet(visit, "return ", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001086 break;
1087 default:
1088 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +00001089 }
1090
1091 return true;
1092}
1093
Olli Etuaho6d40bbd2016-09-30 13:49:38 +01001094void TOutputGLSLBase::visitCodeBlock(TIntermBlock *node)
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001095{
zmo@google.com5601ea02011-06-10 18:23:25 +00001096 TInfoSinkBase &out = objSink();
Yunchao He4f285442017-04-21 12:15:49 +08001097 if (node != nullptr)
zmo@google.com5601ea02011-06-10 18:23:25 +00001098 {
1099 node->traverse(this);
1100 // Single statements not part of a sequence need to be terminated
1101 // with semi-colon.
1102 if (isSingleStatement(node))
1103 out << ";\n";
1104 }
1105 else
1106 {
1107 out << "{\n}\n"; // Empty code block.
1108 }
1109}
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001110
Olli Etuahofbb1c792018-01-19 16:26:59 +02001111ImmutableString TOutputGLSLBase::getTypeName(const TType &type)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001112{
Jamie Madill6276b922017-09-25 02:35:57 -04001113 return GetTypeName(type, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001114}
1115
Olli Etuahofbb1c792018-01-19 16:26:59 +02001116ImmutableString TOutputGLSLBase::hashName(const TSymbol *symbol)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001117{
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001118 return HashName(symbol, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001119}
1120
Olli Etuahofbb1c792018-01-19 16:26:59 +02001121ImmutableString TOutputGLSLBase::hashFieldName(const TSymbol *containingStruct,
1122 const ImmutableString &fieldName)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001123{
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001124 if (containingStruct->symbolType() == SymbolType::UserDefined ||
1125 containingStruct->symbolType() == SymbolType::Empty)
Olli Etuaho09b04a22016-12-15 13:30:26 +00001126 {
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001127 return HashName(fieldName, mHashFunction, &mNameMap);
Olli Etuaho09b04a22016-12-15 13:30:26 +00001128 }
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001129 else
1130 {
1131 return fieldName;
1132 }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001133}
1134
Olli Etuahofbb1c792018-01-19 16:26:59 +02001135ImmutableString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunction *func)
Olli Etuaho1bb85282017-12-14 13:39:53 +02001136{
1137 if (func->isMain())
1138 {
Olli Etuahobed35d72017-12-20 16:36:26 +02001139 return func->name();
Olli Etuaho1bb85282017-12-14 13:39:53 +02001140 }
1141 else
1142 {
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001143 return hashName(func);
Olli Etuaho1bb85282017-12-14 13:39:53 +02001144 }
1145}
1146
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001147bool TOutputGLSLBase::structDeclared(const TStructure *structure) const
Jamie Madill98493dd2013-07-08 14:39:03 -04001148{
Zhenyao Mo904a9162014-05-09 14:07:45 -07001149 ASSERT(structure);
Olli Etuaho9d4d7f02017-12-07 17:11:41 +01001150 if (structure->symbolType() == SymbolType::Empty)
Zhenyao Mo904a9162014-05-09 14:07:45 -07001151 {
Jamie Madill01f85ac2014-06-06 11:55:04 -04001152 return false;
Zhenyao Mo904a9162014-05-09 14:07:45 -07001153 }
Jamie Madill01f85ac2014-06-06 11:55:04 -04001154
Olli Etuaho97fa8552017-11-28 16:28:42 +02001155 return (mDeclaredStructs.count(structure->uniqueId().get()) > 0);
Jamie Madill98493dd2013-07-08 14:39:03 -04001156}
1157
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001158void TOutputGLSLBase::declareStruct(const TStructure *structure)
Jamie Madill98493dd2013-07-08 14:39:03 -04001159{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001160 TInfoSinkBase &out = objSink();
Jamie Madill98493dd2013-07-08 14:39:03 -04001161
Olli Etuahobed35d72017-12-20 16:36:26 +02001162 out << "struct ";
1163
1164 if (structure->symbolType() != SymbolType::Empty)
1165 {
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001166 out << hashName(structure) << " ";
Olli Etuahobed35d72017-12-20 16:36:26 +02001167 }
1168 out << "{\n";
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001169 const TFieldList &fields = structure->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -04001170 for (size_t i = 0; i < fields.size(); ++i)
1171 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001172 const TField *field = fields[i];
Jamie Madill98493dd2013-07-08 14:39:03 -04001173 if (writeVariablePrecision(field->type()->getPrecision()))
1174 out << " ";
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001175 out << getTypeName(*field->type()) << " " << hashFieldName(structure, field->name());
Jamie Madill98493dd2013-07-08 14:39:03 -04001176 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001177 out << ArrayString(*field->type());
Jamie Madill98493dd2013-07-08 14:39:03 -04001178 out << ";\n";
1179 }
1180 out << "}";
Zhenyao Mo904a9162014-05-09 14:07:45 -07001181}
Jamie Madill98493dd2013-07-08 14:39:03 -04001182
Geoff Langbdcc54a2015-09-02 13:09:48 -04001183void TOutputGLSLBase::declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock)
1184{
1185 TInfoSinkBase &out = objSink();
1186
1187 out << "layout(";
1188
1189 switch (interfaceBlock->blockStorage())
1190 {
1191 case EbsUnspecified:
1192 case EbsShared:
1193 // Default block storage is shared.
1194 out << "shared";
1195 break;
1196
1197 case EbsPacked:
1198 out << "packed";
1199 break;
1200
1201 case EbsStd140:
1202 out << "std140";
1203 break;
1204
Qin Jiajiaca68d982017-09-18 16:41:56 +08001205 case EbsStd430:
1206 out << "std430";
1207 break;
1208
Geoff Langbdcc54a2015-09-02 13:09:48 -04001209 default:
1210 UNREACHABLE();
1211 break;
1212 }
1213
Jiajia Qinfeb2c632017-12-08 17:59:19 +08001214 if (interfaceBlock->blockBinding() >= 0)
Jiajia Qin729b2c62017-08-14 09:36:11 +08001215 {
Jiajia Qin729b2c62017-08-14 09:36:11 +08001216 out << ", ";
Olli Etuaho3de27032017-11-30 12:16:47 +02001217 out << "binding = " << interfaceBlock->blockBinding();
Geoff Langbdcc54a2015-09-02 13:09:48 -04001218 }
1219
1220 out << ") ";
1221}
1222
1223void TOutputGLSLBase::declareInterfaceBlock(const TInterfaceBlock *interfaceBlock)
1224{
1225 TInfoSinkBase &out = objSink();
1226
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001227 out << hashName(interfaceBlock) << "{\n";
Geoff Langbdcc54a2015-09-02 13:09:48 -04001228 const TFieldList &fields = interfaceBlock->fields();
Olli Etuaho3de27032017-11-30 12:16:47 +02001229 for (const TField *field : fields)
Geoff Langbdcc54a2015-09-02 13:09:48 -04001230 {
Olli Etuaho3de27032017-11-30 12:16:47 +02001231 if (field->type()->isMatrix() || field->type()->isStructureContainingMatrices())
1232 {
1233 out << "layout(";
1234 switch (field->type()->getLayoutQualifier().matrixPacking)
1235 {
1236 case EmpUnspecified:
1237 case EmpColumnMajor:
1238 // Default matrix packing is column major.
1239 out << "column_major";
1240 break;
1241
1242 case EmpRowMajor:
1243 out << "row_major";
1244 break;
1245
1246 default:
1247 UNREACHABLE();
1248 break;
1249 }
1250 out << ") ";
1251 }
1252
Geoff Langbdcc54a2015-09-02 13:09:48 -04001253 if (writeVariablePrecision(field->type()->getPrecision()))
1254 out << " ";
Olli Etuaho8b5e8fd2017-12-15 14:59:15 +02001255 out << getTypeName(*field->type()) << " " << hashFieldName(interfaceBlock, field->name());
Geoff Langbdcc54a2015-09-02 13:09:48 -04001256 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001257 out << ArrayString(*field->type());
Geoff Langbdcc54a2015-09-02 13:09:48 -04001258 out << ";\n";
1259 }
1260 out << "}";
1261}
Jamie Madill45bcc782016-11-07 13:58:48 -05001262
Shaob5cc1192017-07-06 10:47:20 +08001263void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out,
1264 sh::TLayoutPrimitiveType inputPrimitive,
1265 int invocations,
1266 sh::TLayoutPrimitiveType outputPrimitive,
1267 int maxVertices)
1268{
1269 // Omit 'invocations = 1'
1270 if (inputPrimitive != EptUndefined || invocations > 1)
1271 {
1272 out << "layout (";
1273
1274 if (inputPrimitive != EptUndefined)
1275 {
1276 out << getGeometryShaderPrimitiveTypeString(inputPrimitive);
1277 }
1278
1279 if (invocations > 1)
1280 {
1281 if (inputPrimitive != EptUndefined)
1282 {
1283 out << ", ";
1284 }
1285 out << "invocations = " << invocations;
1286 }
1287 out << ") in;\n";
1288 }
1289
1290 if (outputPrimitive != EptUndefined || maxVertices != -1)
1291 {
1292 out << "layout (";
1293
1294 if (outputPrimitive != EptUndefined)
1295 {
1296 out << getGeometryShaderPrimitiveTypeString(outputPrimitive);
1297 }
1298
1299 if (maxVertices != -1)
1300 {
1301 if (outputPrimitive != EptUndefined)
1302 {
1303 out << ", ";
1304 }
1305 out << "max_vertices = " << maxVertices;
1306 }
1307 out << ") out;\n";
1308 }
1309}
1310
Jamie Madill2a9e1072017-09-22 11:31:57 -04001311// If SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS is enabled, layout qualifiers are spilled whenever
1312// variables with specified layout qualifiers are copied. Additional checks are needed against the
1313// type and storage qualifier of the variable to verify that layout qualifiers have to be outputted.
1314// TODO (mradev): Fix layout qualifier spilling in ScalarizeVecAndMatConstructorArgs and remove
1315// NeedsToWriteLayoutQualifier.
1316bool NeedsToWriteLayoutQualifier(const TType &type)
1317{
1318 if (type.getBasicType() == EbtInterfaceBlock)
1319 {
1320 return false;
1321 }
1322
1323 const TLayoutQualifier &layoutQualifier = type.getLayoutQualifier();
1324
1325 if ((type.getQualifier() == EvqFragmentOut || type.getQualifier() == EvqVertexIn ||
1326 IsVarying(type.getQualifier())) &&
1327 layoutQualifier.location >= 0)
1328 {
1329 return true;
1330 }
1331
1332 if (type.getQualifier() == EvqFragmentOut && layoutQualifier.yuv == true)
1333 {
1334 return true;
1335 }
1336
1337 if (IsOpaqueType(type.getBasicType()) && layoutQualifier.binding != -1)
1338 {
1339 return true;
1340 }
1341
1342 if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified)
1343 {
1344 return true;
1345 }
1346 return false;
1347}
1348
Jamie Madill45bcc782016-11-07 13:58:48 -05001349} // namespace sh