blob: 9f0fb68c9c2da6a651d93928688c023a794566c7 [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 {
263 TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
264 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
313 if (!structure->name().empty())
314 {
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 {
320 TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
321 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 Etuaho0982a2b2016-11-01 15:13:46 +0000342 if (!arg->getName().getString().empty())
343 out << " " << hashName(arg->getName());
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 Etuaho0982a2b2016-11-01 15:13:46 +0000361 out << hashName(TName(structure->name())) << "(";
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();
Corentin Wallez1b896c62016-11-16 13:10:44 -0500436 out << hashVariableName(node->getName());
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{
444 writeConstantUnion(node->getType(), node->getUnionArrayPointer());
445}
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
585 TString fieldName = field->name();
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300586 if (!mSymbolTable->findBuiltIn(structure->name(), mShaderVersion))
Olli Etuaho0982a2b2016-11-01 15:13:46 +0000587 fieldName = hashName(TName(fieldName));
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100588
589 out << fieldName;
590 visitChildren = false;
591 }
592 break;
593 case EOpIndexDirectInterfaceBlock:
594 if (visit == InVisit)
595 {
596 out << ".";
597 const TInterfaceBlock *interfaceBlock =
598 node->getLeft()->getType().getInterfaceBlock();
599 const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
600 const TField *field = interfaceBlock->fields()[index->getIConst(0)];
601
602 TString fieldName = field->name();
Jiawei Shao65c56dd2017-10-13 16:18:57 +0800603 if (!mSymbolTable->findBuiltIn(interfaceBlock->name(), mShaderVersion))
604 {
605 fieldName = hashName(TName(fieldName));
606 }
607 else
608 {
609 ASSERT(interfaceBlock->name() == "gl_PerVertex");
610 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700611
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100612 out << fieldName;
613 visitChildren = false;
614 }
615 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400616
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100617 case EOpAdd:
618 writeTriplet(visit, "(", " + ", ")");
619 break;
620 case EOpSub:
621 writeTriplet(visit, "(", " - ", ")");
622 break;
623 case EOpMul:
624 writeTriplet(visit, "(", " * ", ")");
625 break;
626 case EOpDiv:
627 writeTriplet(visit, "(", " / ", ")");
628 break;
629 case EOpIMod:
630 writeTriplet(visit, "(", " % ", ")");
631 break;
632 case EOpBitShiftLeft:
633 writeTriplet(visit, "(", " << ", ")");
634 break;
635 case EOpBitShiftRight:
636 writeTriplet(visit, "(", " >> ", ")");
637 break;
638 case EOpBitwiseAnd:
639 writeTriplet(visit, "(", " & ", ")");
640 break;
641 case EOpBitwiseXor:
642 writeTriplet(visit, "(", " ^ ", ")");
643 break;
644 case EOpBitwiseOr:
645 writeTriplet(visit, "(", " | ", ")");
646 break;
Geoff Lang6e360422015-09-02 15:54:36 -0400647
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100648 case EOpEqual:
649 writeTriplet(visit, "(", " == ", ")");
650 break;
651 case EOpNotEqual:
652 writeTriplet(visit, "(", " != ", ")");
653 break;
654 case EOpLessThan:
655 writeTriplet(visit, "(", " < ", ")");
656 break;
657 case EOpGreaterThan:
658 writeTriplet(visit, "(", " > ", ")");
659 break;
660 case EOpLessThanEqual:
661 writeTriplet(visit, "(", " <= ", ")");
662 break;
663 case EOpGreaterThanEqual:
664 writeTriplet(visit, "(", " >= ", ")");
665 break;
daniel@transgaming.com97b16d12013-02-01 03:20:42 +0000666
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100667 // Notice the fall-through.
668 case EOpVectorTimesScalar:
669 case EOpVectorTimesMatrix:
670 case EOpMatrixTimesVector:
671 case EOpMatrixTimesScalar:
672 case EOpMatrixTimesMatrix:
673 writeTriplet(visit, "(", " * ", ")");
674 break;
Olli Etuaho31b5fc62015-01-16 12:13:36 +0200675
Olli Etuaho4db7ded2016-10-13 12:23:11 +0100676 case EOpLogicalOr:
677 writeTriplet(visit, "(", " || ", ")");
678 break;
679 case EOpLogicalXor:
680 writeTriplet(visit, "(", " ^^ ", ")");
681 break;
682 case EOpLogicalAnd:
683 writeTriplet(visit, "(", " && ", ")");
684 break;
685 default:
686 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000687 }
688
689 return visitChildren;
690}
691
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700692bool TOutputGLSLBase::visitUnary(Visit visit, TIntermUnary *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000693{
zmo@google.com32e97312011-08-24 01:03:11 +0000694 TString preString;
695 TString postString = ")";
696
zmo@google.com5601ea02011-06-10 18:23:25 +0000697 switch (node->getOp())
698 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500699 case EOpNegative:
700 preString = "(-";
701 break;
702 case EOpPositive:
703 preString = "(+";
704 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500705 case EOpLogicalNot:
706 preString = "(!";
707 break;
708 case EOpBitwiseNot:
709 preString = "(~";
710 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000711
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500712 case EOpPostIncrement:
713 preString = "(";
714 postString = "++)";
715 break;
716 case EOpPostDecrement:
717 preString = "(";
718 postString = "--)";
719 break;
720 case EOpPreIncrement:
721 preString = "(++";
722 break;
723 case EOpPreDecrement:
724 preString = "(--";
725 break;
Olli Etuahobb5a7e22017-08-30 13:03:12 +0300726 case EOpArrayLength:
727 preString = "((";
728 postString = ").length())";
729 break;
zmo@google.com5601ea02011-06-10 18:23:25 +0000730
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500731 case EOpRadians:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500732 case EOpDegrees:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500733 case EOpSin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500734 case EOpCos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500735 case EOpTan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500736 case EOpAsin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500737 case EOpAcos:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500738 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500739 case EOpSinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500740 case EOpCosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500741 case EOpTanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500742 case EOpAsinh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500743 case EOpAcosh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500744 case EOpAtanh:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500745 case EOpExp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500746 case EOpLog:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500747 case EOpExp2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500748 case EOpLog2:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500749 case EOpSqrt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500750 case EOpInverseSqrt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500751 case EOpAbs:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500752 case EOpSign:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500753 case EOpFloor:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500754 case EOpTrunc:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500755 case EOpRound:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500756 case EOpRoundEven:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500757 case EOpCeil:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500758 case EOpFract:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500759 case EOpIsNan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500760 case EOpIsInf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500761 case EOpFloatBitsToInt:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500762 case EOpFloatBitsToUint:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500763 case EOpIntBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500764 case EOpUintBitsToFloat:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500765 case EOpPackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500766 case EOpPackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500767 case EOpPackHalf2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500768 case EOpUnpackSnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500769 case EOpUnpackUnorm2x16:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500770 case EOpUnpackHalf2x16:
Olli Etuaho25aef452017-01-29 16:15:44 -0800771 case EOpPackUnorm4x8:
772 case EOpPackSnorm4x8:
773 case EOpUnpackUnorm4x8:
774 case EOpUnpackSnorm4x8:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500775 case EOpLength:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500776 case EOpNormalize:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500777 case EOpDFdx:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500778 case EOpDFdy:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500779 case EOpFwidth:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500780 case EOpTranspose:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500781 case EOpDeterminant:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500782 case EOpInverse:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500783 case EOpAny:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500784 case EOpAll:
Olli Etuahod68924e2017-01-02 17:34:40 +0000785 case EOpLogicalNotComponentWise:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000786 case EOpBitfieldReverse:
787 case EOpBitCount:
788 case EOpFindLSB:
789 case EOpFindMSB:
Olli Etuahod68924e2017-01-02 17:34:40 +0000790 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
791 return true;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500792 default:
793 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +0000794 }
795
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800796 writeTriplet(visit, preString.c_str(), nullptr, postString.c_str());
zmo@google.com32e97312011-08-24 01:03:11 +0000797
zmo@google.com5601ea02011-06-10 18:23:25 +0000798 return true;
799}
800
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300801bool TOutputGLSLBase::visitTernary(Visit visit, TIntermTernary *node)
802{
803 TInfoSinkBase &out = objSink();
804 // Notice two brackets at the beginning and end. The outer ones
805 // encapsulate the whole ternary expression. This preserves the
806 // order of precedence when ternary expressions are used in a
807 // compound expression, i.e., c = 2 * (a < b ? 1 : 2).
808 out << "((";
809 node->getCondition()->traverse(this);
810 out << ") ? (";
811 node->getTrueExpression()->traverse(this);
812 out << ") : (";
813 node->getFalseExpression()->traverse(this);
814 out << "))";
815 return false;
816}
817
Olli Etuaho57961272016-09-14 13:57:46 +0300818bool TOutputGLSLBase::visitIfElse(Visit visit, TIntermIfElse *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000819{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700820 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000821
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300822 out << "if (";
823 node->getCondition()->traverse(this);
824 out << ")\n";
zmo@google.com5601ea02011-06-10 18:23:25 +0000825
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300826 visitCodeBlock(node->getTrueBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000827
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300828 if (node->getFalseBlock())
829 {
830 out << "else\n";
831 visitCodeBlock(node->getFalseBlock());
zmo@google.com5601ea02011-06-10 18:23:25 +0000832 }
833 return false;
834}
835
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200836bool TOutputGLSLBase::visitSwitch(Visit visit, TIntermSwitch *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200837{
Olli Etuaho923ecef2017-10-11 12:01:38 +0300838 ASSERT(node->getStatementList());
839 writeTriplet(visit, "switch (", ") ", nullptr);
840 // The curly braces get written when visiting the statementList aggregate
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200841 return true;
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200842}
843
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200844bool TOutputGLSLBase::visitCase(Visit visit, TIntermCase *node)
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200845{
Olli Etuaho01cd8af2015-02-20 10:39:20 +0200846 if (node->hasCondition())
847 {
848 writeTriplet(visit, "case (", nullptr, "):\n");
849 return true;
850 }
851 else
852 {
853 TInfoSinkBase &out = objSink();
854 out << "default:\n";
855 return false;
856 }
Olli Etuaho3c1dfb52015-02-20 11:34:03 +0200857}
858
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100859bool TOutputGLSLBase::visitBlock(Visit visit, TIntermBlock *node)
860{
861 TInfoSinkBase &out = objSink();
862 // Scope the blocks except when at the global scope.
863 if (mDepth > 0)
864 {
865 out << "{\n";
866 }
867
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100868 for (TIntermSequence::const_iterator iter = node->getSequence()->begin();
869 iter != node->getSequence()->end(); ++iter)
870 {
871 TIntermNode *curNode = *iter;
872 ASSERT(curNode != nullptr);
873 curNode->traverse(this);
874
875 if (isSingleStatement(curNode))
876 out << ";\n";
877 }
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100878
879 // Scope the blocks except when at the global scope.
880 if (mDepth > 0)
881 {
882 out << "}\n";
883 }
884 return false;
885}
886
Olli Etuaho336b1472016-10-05 16:37:55 +0100887bool TOutputGLSLBase::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
888{
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000889 TIntermFunctionPrototype *prototype = node->getFunctionPrototype();
890 prototype->traverse(this);
Olli Etuaho336b1472016-10-05 16:37:55 +0100891 visitCodeBlock(node->getBody());
Olli Etuaho336b1472016-10-05 16:37:55 +0100892
893 // Fully processed; no need to visit children.
894 return false;
895}
896
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000897bool TOutputGLSLBase::visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node)
898{
899 TInfoSinkBase &out = objSink();
900 ASSERT(visit == PreVisit);
901 const TIntermSymbol *symbol = node->getSymbol();
902 out << "invariant " << hashVariableName(symbol->getName());
903 return false;
904}
905
Olli Etuaho16c745a2017-01-16 17:02:27 +0000906bool TOutputGLSLBase::visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node)
907{
908 TInfoSinkBase &out = objSink();
909 ASSERT(visit == PreVisit);
910
911 const TType &type = node->getType();
912 writeVariableType(type);
913 if (type.isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +0300914 out << ArrayString(type);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000915
Olli Etuahoec9232b2017-03-27 17:01:37 +0300916 out << " " << hashFunctionNameIfNeeded(*node->getFunctionSymbolInfo());
Olli Etuaho16c745a2017-01-16 17:02:27 +0000917
918 out << "(";
919 writeFunctionParameters(*(node->getSequence()));
920 out << ")";
921
922 return false;
923}
924
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700925bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
zmo@google.com5601ea02011-06-10 18:23:25 +0000926{
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500927 bool visitChildren = true;
928 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +0000929 switch (node->getOp())
930 {
Olli Etuaho1ecd14b2017-01-26 13:54:15 -0800931 case EOpCallFunctionInAST:
932 case EOpCallInternalRawFunction:
933 case EOpCallBuiltInFunction:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500934 // Function call.
935 if (visit == PreVisit)
Olli Etuahoec9232b2017-03-27 17:01:37 +0300936 {
937 if (node->getOp() == EOpCallBuiltInFunction)
938 {
939 out << translateTextureFunction(node->getFunctionSymbolInfo()->getName());
940 }
941 else
942 {
943 out << hashFunctionNameIfNeeded(*node->getFunctionSymbolInfo());
944 }
945 out << "(";
946 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500947 else if (visit == InVisit)
948 out << ", ";
949 else
950 out << ")";
951 break;
Olli Etuaho8fab3202017-05-08 18:22:22 +0300952 case EOpConstruct:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500953 writeConstructorTriplet(visit, node->getType());
954 break;
Olli Etuahoe39706d2014-12-30 16:40:36 +0200955
Olli Etuahoe1805592017-01-02 16:41:20 +0000956 case EOpEqualComponentWise:
957 case EOpNotEqualComponentWise:
958 case EOpLessThanComponentWise:
959 case EOpGreaterThanComponentWise:
960 case EOpLessThanEqualComponentWise:
961 case EOpGreaterThanEqualComponentWise:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500962 case EOpMod:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500963 case EOpModf:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500964 case EOpPow:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500965 case EOpAtan:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500966 case EOpMin:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500967 case EOpMax:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500968 case EOpClamp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500969 case EOpMix:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500970 case EOpStep:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500971 case EOpSmoothStep:
Olli Etuaho74da73f2017-02-01 15:37:48 +0000972 case EOpFrexp:
973 case EOpLdexp:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500974 case EOpDistance:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500975 case EOpDot:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500976 case EOpCross:
Jamie Madille72595b2017-06-06 15:12:26 -0400977 case EOpFaceforward:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500978 case EOpReflect:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500979 case EOpRefract:
Olli Etuahoe1805592017-01-02 16:41:20 +0000980 case EOpMulMatrixComponentWise:
981 case EOpOuterProduct:
Olli Etuaho9250cb22017-01-21 10:51:27 +0000982 case EOpBitfieldExtract:
983 case EOpBitfieldInsert:
984 case EOpUaddCarry:
985 case EOpUsubBorrow:
986 case EOpUmulExtended:
987 case EOpImulExtended:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300988 case EOpBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300989 case EOpMemoryBarrier:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300990 case EOpMemoryBarrierAtomicCounter:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300991 case EOpMemoryBarrierBuffer:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300992 case EOpMemoryBarrierImage:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300993 case EOpMemoryBarrierShared:
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300994 case EOpGroupMemoryBarrier:
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800995 case EOpEmitVertex:
996 case EOpEndPrimitive:
Olli Etuahod68924e2017-01-02 17:34:40 +0000997 writeBuiltInFunctionTriplet(visit, node->getOp(), node->getUseEmulatedFunction());
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300998 break;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500999 default:
1000 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +00001001 }
zmo@google.com5601ea02011-06-10 18:23:25 +00001002 return visitChildren;
1003}
1004
Olli Etuaho13389b62016-10-16 11:48:18 +01001005bool TOutputGLSLBase::visitDeclaration(Visit visit, TIntermDeclaration *node)
1006{
1007 TInfoSinkBase &out = objSink();
1008
1009 // Variable declaration.
1010 if (visit == PreVisit)
1011 {
1012 const TIntermSequence &sequence = *(node->getSequence());
Jamie Madill2a9e1072017-09-22 11:31:57 -04001013 TIntermTyped *variable = sequence.front()->getAsTyped();
1014 writeLayoutQualifier(variable);
Olli Etuaho13389b62016-10-16 11:48:18 +01001015 writeVariableType(variable->getType());
Olli Etuaho39f74df2017-11-20 16:09:57 +02001016 if (variable->getAsSymbolNode() == nullptr ||
1017 !variable->getAsSymbolNode()->getSymbol().empty())
1018 {
1019 out << " ";
1020 }
1021 mDeclaringVariable = true;
Olli Etuaho13389b62016-10-16 11:48:18 +01001022 }
1023 else if (visit == InVisit)
1024 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001025 UNREACHABLE();
Olli Etuaho13389b62016-10-16 11:48:18 +01001026 }
1027 else
1028 {
Olli Etuaho39f74df2017-11-20 16:09:57 +02001029 mDeclaringVariable = false;
Olli Etuaho13389b62016-10-16 11:48:18 +01001030 }
1031 return true;
1032}
1033
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001034bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001035{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001036 TInfoSinkBase &out = objSink();
zmo@google.com5601ea02011-06-10 18:23:25 +00001037
zmo@google.com5601ea02011-06-10 18:23:25 +00001038 TLoopType loopType = node->getType();
Corentin Wallez7258e302015-09-22 10:40:24 -07001039
zmo@google.com5601ea02011-06-10 18:23:25 +00001040 if (loopType == ELoopFor) // for loop
1041 {
Corentin Wallez1b896c62016-11-16 13:10:44 -05001042 out << "for (";
1043 if (node->getInit())
1044 node->getInit()->traverse(this);
1045 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001046
Corentin Wallez1b896c62016-11-16 13:10:44 -05001047 if (node->getCondition())
1048 node->getCondition()->traverse(this);
1049 out << "; ";
zmo@google.com5601ea02011-06-10 18:23:25 +00001050
Corentin Wallez1b896c62016-11-16 13:10:44 -05001051 if (node->getExpression())
1052 node->getExpression()->traverse(this);
1053 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001054
Corentin Wallez1b896c62016-11-16 13:10:44 -05001055 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001056 }
1057 else if (loopType == ELoopWhile) // while loop
1058 {
1059 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001060 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001061 node->getCondition()->traverse(this);
1062 out << ")\n";
Corentin Wallez7258e302015-09-22 10:40:24 -07001063
1064 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001065 }
1066 else // do-while loop
1067 {
1068 ASSERT(loopType == ELoopDoWhile);
1069 out << "do\n";
zmo@google.com5601ea02011-06-10 18:23:25 +00001070
zmo@google.com5601ea02011-06-10 18:23:25 +00001071 visitCodeBlock(node->getBody());
zmo@google.com5601ea02011-06-10 18:23:25 +00001072
zmo@google.com5601ea02011-06-10 18:23:25 +00001073 out << "while (";
Yunchao He4f285442017-04-21 12:15:49 +08001074 ASSERT(node->getCondition() != nullptr);
zmo@google.com5601ea02011-06-10 18:23:25 +00001075 node->getCondition()->traverse(this);
1076 out << ");\n";
1077 }
Corentin Wallez7258e302015-09-22 10:40:24 -07001078
zmo@google.com5601ea02011-06-10 18:23:25 +00001079 // No need to visit children. They have been already processed in
1080 // this function.
1081 return false;
1082}
1083
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001084bool TOutputGLSLBase::visitBranch(Visit visit, TIntermBranch *node)
zmo@google.com5601ea02011-06-10 18:23:25 +00001085{
1086 switch (node->getFlowOp())
1087 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001088 case EOpKill:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001089 writeTriplet(visit, "discard", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001090 break;
1091 case EOpBreak:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001092 writeTriplet(visit, "break", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001093 break;
1094 case EOpContinue:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001095 writeTriplet(visit, "continue", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001096 break;
1097 case EOpReturn:
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001098 writeTriplet(visit, "return ", nullptr, nullptr);
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001099 break;
1100 default:
1101 UNREACHABLE();
zmo@google.com5601ea02011-06-10 18:23:25 +00001102 }
1103
1104 return true;
1105}
1106
Olli Etuaho6d40bbd2016-09-30 13:49:38 +01001107void TOutputGLSLBase::visitCodeBlock(TIntermBlock *node)
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001108{
zmo@google.com5601ea02011-06-10 18:23:25 +00001109 TInfoSinkBase &out = objSink();
Yunchao He4f285442017-04-21 12:15:49 +08001110 if (node != nullptr)
zmo@google.com5601ea02011-06-10 18:23:25 +00001111 {
1112 node->traverse(this);
1113 // Single statements not part of a sequence need to be terminated
1114 // with semi-colon.
1115 if (isSingleStatement(node))
1116 out << ";\n";
1117 }
1118 else
1119 {
1120 out << "{\n}\n"; // Empty code block.
1121 }
1122}
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001123
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001124TString TOutputGLSLBase::getTypeName(const TType &type)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001125{
Jamie Madill6276b922017-09-25 02:35:57 -04001126 return GetTypeName(type, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001127}
1128
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001129TString TOutputGLSLBase::hashName(const TName &name)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001130{
Olli Etuaho855d9642017-05-17 14:05:06 +03001131 return HashName(name, mHashFunction, &mNameMap);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001132}
1133
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001134TString TOutputGLSLBase::hashVariableName(const TName &name)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001135{
Olli Etuaho855d9642017-05-17 14:05:06 +03001136 if (mSymbolTable->findBuiltIn(name.getString(), mShaderVersion) != nullptr ||
1137 name.getString().substr(0, 3) == "gl_")
Olli Etuaho09b04a22016-12-15 13:30:26 +00001138 {
1139 if (mCompileOptions & SH_TRANSLATE_VIEWID_OVR_TO_UNIFORM &&
1140 name.getString() == "gl_ViewID_OVR")
1141 {
Olli Etuaho2f90a9b2017-01-10 12:27:56 +00001142 TName uniformName(TString("ViewID_OVR"));
Olli Etuaho09b04a22016-12-15 13:30:26 +00001143 uniformName.setInternal(true);
1144 return hashName(uniformName);
1145 }
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001146 return name.getString();
Olli Etuaho09b04a22016-12-15 13:30:26 +00001147 }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001148 return hashName(name);
1149}
1150
Olli Etuahoec9232b2017-03-27 17:01:37 +03001151TString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunctionSymbolInfo &info)
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001152{
Olli Etuaho855d9642017-05-17 14:05:06 +03001153 if (info.isMain())
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001154 {
Olli Etuahoec9232b2017-03-27 17:01:37 +03001155 return info.getName();
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001156 }
Olli Etuaho59f9a642015-08-06 20:38:26 +03001157 else
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001158 {
Olli Etuahoec9232b2017-03-27 17:01:37 +03001159 return hashName(info.getNameObj());
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001160 }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00001161}
Jamie Madill98493dd2013-07-08 14:39:03 -04001162
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001163bool TOutputGLSLBase::structDeclared(const TStructure *structure) const
Jamie Madill98493dd2013-07-08 14:39:03 -04001164{
Zhenyao Mo904a9162014-05-09 14:07:45 -07001165 ASSERT(structure);
Jamie Madill01f85ac2014-06-06 11:55:04 -04001166 if (structure->name().empty())
Zhenyao Mo904a9162014-05-09 14:07:45 -07001167 {
Jamie Madill01f85ac2014-06-06 11:55:04 -04001168 return false;
Zhenyao Mo904a9162014-05-09 14:07:45 -07001169 }
Jamie Madill01f85ac2014-06-06 11:55:04 -04001170
Olli Etuaho97fa8552017-11-28 16:28:42 +02001171 return (mDeclaredStructs.count(structure->uniqueId().get()) > 0);
Jamie Madill98493dd2013-07-08 14:39:03 -04001172}
1173
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001174void TOutputGLSLBase::declareStruct(const TStructure *structure)
Jamie Madill98493dd2013-07-08 14:39:03 -04001175{
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001176 TInfoSinkBase &out = objSink();
Jamie Madill98493dd2013-07-08 14:39:03 -04001177
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001178 out << "struct " << hashName(TName(structure->name())) << "{\n";
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001179 const TFieldList &fields = structure->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -04001180 for (size_t i = 0; i < fields.size(); ++i)
1181 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -07001182 const TField *field = fields[i];
Jamie Madill98493dd2013-07-08 14:39:03 -04001183 if (writeVariablePrecision(field->type()->getPrecision()))
1184 out << " ";
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001185 out << getTypeName(*field->type()) << " " << hashName(TName(field->name()));
Jamie Madill98493dd2013-07-08 14:39:03 -04001186 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001187 out << ArrayString(*field->type());
Jamie Madill98493dd2013-07-08 14:39:03 -04001188 out << ";\n";
1189 }
1190 out << "}";
Zhenyao Mo904a9162014-05-09 14:07:45 -07001191}
Jamie Madill98493dd2013-07-08 14:39:03 -04001192
Geoff Langbdcc54a2015-09-02 13:09:48 -04001193void TOutputGLSLBase::declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock)
1194{
1195 TInfoSinkBase &out = objSink();
1196
1197 out << "layout(";
1198
1199 switch (interfaceBlock->blockStorage())
1200 {
1201 case EbsUnspecified:
1202 case EbsShared:
1203 // Default block storage is shared.
1204 out << "shared";
1205 break;
1206
1207 case EbsPacked:
1208 out << "packed";
1209 break;
1210
1211 case EbsStd140:
1212 out << "std140";
1213 break;
1214
Qin Jiajiaca68d982017-09-18 16:41:56 +08001215 case EbsStd430:
1216 out << "std430";
1217 break;
1218
Geoff Langbdcc54a2015-09-02 13:09:48 -04001219 default:
1220 UNREACHABLE();
1221 break;
1222 }
1223
Jiajia Qin729b2c62017-08-14 09:36:11 +08001224 if (interfaceBlock->blockBinding() > 0)
1225 {
Jiajia Qin729b2c62017-08-14 09:36:11 +08001226 out << ", ";
Olli Etuaho3de27032017-11-30 12:16:47 +02001227 out << "binding = " << interfaceBlock->blockBinding();
Geoff Langbdcc54a2015-09-02 13:09:48 -04001228 }
1229
1230 out << ") ";
1231}
1232
1233void TOutputGLSLBase::declareInterfaceBlock(const TInterfaceBlock *interfaceBlock)
1234{
1235 TInfoSinkBase &out = objSink();
1236
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001237 out << hashName(TName(interfaceBlock->name())) << "{\n";
Geoff Langbdcc54a2015-09-02 13:09:48 -04001238 const TFieldList &fields = interfaceBlock->fields();
Olli Etuaho3de27032017-11-30 12:16:47 +02001239 for (const TField *field : fields)
Geoff Langbdcc54a2015-09-02 13:09:48 -04001240 {
Olli Etuaho3de27032017-11-30 12:16:47 +02001241 if (field->type()->isMatrix() || field->type()->isStructureContainingMatrices())
1242 {
1243 out << "layout(";
1244 switch (field->type()->getLayoutQualifier().matrixPacking)
1245 {
1246 case EmpUnspecified:
1247 case EmpColumnMajor:
1248 // Default matrix packing is column major.
1249 out << "column_major";
1250 break;
1251
1252 case EmpRowMajor:
1253 out << "row_major";
1254 break;
1255
1256 default:
1257 UNREACHABLE();
1258 break;
1259 }
1260 out << ") ";
1261 }
1262
Geoff Langbdcc54a2015-09-02 13:09:48 -04001263 if (writeVariablePrecision(field->type()->getPrecision()))
1264 out << " ";
Olli Etuaho0982a2b2016-11-01 15:13:46 +00001265 out << getTypeName(*field->type()) << " " << hashName(TName(field->name()));
Geoff Langbdcc54a2015-09-02 13:09:48 -04001266 if (field->type()->isArray())
Olli Etuaho96f6adf2017-08-16 11:18:54 +03001267 out << ArrayString(*field->type());
Geoff Langbdcc54a2015-09-02 13:09:48 -04001268 out << ";\n";
1269 }
1270 out << "}";
1271}
Jamie Madill45bcc782016-11-07 13:58:48 -05001272
Shaob5cc1192017-07-06 10:47:20 +08001273void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out,
1274 sh::TLayoutPrimitiveType inputPrimitive,
1275 int invocations,
1276 sh::TLayoutPrimitiveType outputPrimitive,
1277 int maxVertices)
1278{
1279 // Omit 'invocations = 1'
1280 if (inputPrimitive != EptUndefined || invocations > 1)
1281 {
1282 out << "layout (";
1283
1284 if (inputPrimitive != EptUndefined)
1285 {
1286 out << getGeometryShaderPrimitiveTypeString(inputPrimitive);
1287 }
1288
1289 if (invocations > 1)
1290 {
1291 if (inputPrimitive != EptUndefined)
1292 {
1293 out << ", ";
1294 }
1295 out << "invocations = " << invocations;
1296 }
1297 out << ") in;\n";
1298 }
1299
1300 if (outputPrimitive != EptUndefined || maxVertices != -1)
1301 {
1302 out << "layout (";
1303
1304 if (outputPrimitive != EptUndefined)
1305 {
1306 out << getGeometryShaderPrimitiveTypeString(outputPrimitive);
1307 }
1308
1309 if (maxVertices != -1)
1310 {
1311 if (outputPrimitive != EptUndefined)
1312 {
1313 out << ", ";
1314 }
1315 out << "max_vertices = " << maxVertices;
1316 }
1317 out << ") out;\n";
1318 }
1319}
1320
Jamie Madill2a9e1072017-09-22 11:31:57 -04001321// If SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS is enabled, layout qualifiers are spilled whenever
1322// variables with specified layout qualifiers are copied. Additional checks are needed against the
1323// type and storage qualifier of the variable to verify that layout qualifiers have to be outputted.
1324// TODO (mradev): Fix layout qualifier spilling in ScalarizeVecAndMatConstructorArgs and remove
1325// NeedsToWriteLayoutQualifier.
1326bool NeedsToWriteLayoutQualifier(const TType &type)
1327{
1328 if (type.getBasicType() == EbtInterfaceBlock)
1329 {
1330 return false;
1331 }
1332
1333 const TLayoutQualifier &layoutQualifier = type.getLayoutQualifier();
1334
1335 if ((type.getQualifier() == EvqFragmentOut || type.getQualifier() == EvqVertexIn ||
1336 IsVarying(type.getQualifier())) &&
1337 layoutQualifier.location >= 0)
1338 {
1339 return true;
1340 }
1341
1342 if (type.getQualifier() == EvqFragmentOut && layoutQualifier.yuv == true)
1343 {
1344 return true;
1345 }
1346
1347 if (IsOpaqueType(type.getBasicType()) && layoutQualifier.binding != -1)
1348 {
1349 return true;
1350 }
1351
1352 if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified)
1353 {
1354 return true;
1355 }
1356 return false;
1357}
1358
Jamie Madill45bcc782016-11-07 13:58:48 -05001359} // namespace sh