2 //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 //Copyright (C) 2012-2013 LunarG, Inc.
7 //Redistribution and use in source and binary forms, with or without
8 //modification, are permitted provided that the following conditions
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
14 // Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
19 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
20 // contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
23 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //POSSIBILITY OF SUCH DAMAGE.
37 #include "localintermediate.h"
38 #include "../Include/InfoSink.h"
48 bool is_positive_infinity(double x) {
50 return _fpclass(x) == _FPCLASS_PINF;
51 #elif defined __ANDROID__ || defined __linux__
52 return std::isinf(x) && (x >= 0);
54 return isinf(x) && (x >= 0);
64 // 1. Show an example of how to iterate tree. Functions can
65 // also directly call Traverse() on children themselves to
66 // have finer grained control over the process than shown here.
67 // See the last function for how to get started.
68 // 2. Print out a text based description of the tree.
72 // Use this class to carry along data from node to node in
75 class TOutputTraverser : public TIntermTraverser {
77 TOutputTraverser(TInfoSink& i) : infoSink(i) { }
79 virtual bool visitBinary(TVisit, TIntermBinary* node);
80 virtual bool visitUnary(TVisit, TIntermUnary* node);
81 virtual bool visitAggregate(TVisit, TIntermAggregate* node);
82 virtual bool visitSelection(TVisit, TIntermSelection* node);
83 virtual void visitConstantUnion(TIntermConstantUnion* node);
84 virtual void visitSymbol(TIntermSymbol* node);
85 virtual bool visitLoop(TVisit, TIntermLoop* node);
86 virtual bool visitBranch(TVisit, TIntermBranch* node);
87 virtual bool visitSwitch(TVisit, TIntermSwitch* node);
91 TOutputTraverser(TOutputTraverser&);
92 TOutputTraverser& operator=(TOutputTraverser&);
96 // Helper functions for printing, not part of traversing.
99 static void OutputTreeText(TInfoSink& infoSink, const TIntermNode* node, const int depth)
103 infoSink.debug << node->getLoc().string << ":";
104 if (node->getLoc().line)
105 infoSink.debug << node->getLoc().line;
107 infoSink.debug << "? ";
109 for (i = 0; i < depth; ++i)
110 infoSink.debug << " ";
114 // The rest of the file are the traversal functions. The last one
115 // is the one that starts the traversal.
117 // Return true from interior nodes to have the external traversal
118 // continue on to children. If you process children yourself,
122 bool TOutputTraverser::visitBinary(TVisit /* visit */, TIntermBinary* node)
124 TInfoSink& out = infoSink;
126 OutputTreeText(out, node, depth);
128 switch (node->getOp()) {
129 case EOpAssign: out.debug << "move second child to first child"; break;
130 case EOpAddAssign: out.debug << "add second child into first child"; break;
131 case EOpSubAssign: out.debug << "subtract second child into first child"; break;
132 case EOpMulAssign: out.debug << "multiply second child into first child"; break;
133 case EOpVectorTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
134 case EOpVectorTimesScalarAssign: out.debug << "vector scale second child into first child"; break;
135 case EOpMatrixTimesScalarAssign: out.debug << "matrix scale second child into first child"; break;
136 case EOpMatrixTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
137 case EOpDivAssign: out.debug << "divide second child into first child"; break;
138 case EOpModAssign: out.debug << "mod second child into first child"; break;
139 case EOpAndAssign: out.debug << "and second child into first child"; break;
140 case EOpInclusiveOrAssign: out.debug << "or second child into first child"; break;
141 case EOpExclusiveOrAssign: out.debug << "exclusive or second child into first child"; break;
142 case EOpLeftShiftAssign: out.debug << "left shift second child into first child"; break;
143 case EOpRightShiftAssign: out.debug << "right shift second child into first child"; break;
145 case EOpIndexDirect: out.debug << "direct index"; break;
146 case EOpIndexIndirect: out.debug << "indirect index"; break;
147 case EOpIndexDirectStruct:
148 out.debug << (*node->getLeft()->getType().getStruct())[node->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst()].type->getFieldName();
149 out.debug << ": direct index for structure"; break;
150 case EOpVectorSwizzle: out.debug << "vector swizzle"; break;
152 case EOpAdd: out.debug << "add"; break;
153 case EOpSub: out.debug << "subtract"; break;
154 case EOpMul: out.debug << "component-wise multiply"; break;
155 case EOpDiv: out.debug << "divide"; break;
156 case EOpMod: out.debug << "mod"; break;
157 case EOpRightShift: out.debug << "right-shift"; break;
158 case EOpLeftShift: out.debug << "left-shift"; break;
159 case EOpAnd: out.debug << "bitwise and"; break;
160 case EOpInclusiveOr: out.debug << "inclusive-or"; break;
161 case EOpExclusiveOr: out.debug << "exclusive-or"; break;
162 case EOpEqual: out.debug << "Compare Equal"; break;
163 case EOpNotEqual: out.debug << "Compare Not Equal"; break;
164 case EOpLessThan: out.debug << "Compare Less Than"; break;
165 case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
166 case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
167 case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
169 case EOpVectorTimesScalar: out.debug << "vector-scale"; break;
170 case EOpVectorTimesMatrix: out.debug << "vector-times-matrix"; break;
171 case EOpMatrixTimesVector: out.debug << "matrix-times-vector"; break;
172 case EOpMatrixTimesScalar: out.debug << "matrix-scale"; break;
173 case EOpMatrixTimesMatrix: out.debug << "matrix-multiply"; break;
175 case EOpLogicalOr: out.debug << "logical-or"; break;
176 case EOpLogicalXor: out.debug << "logical-xor"; break;
177 case EOpLogicalAnd: out.debug << "logical-and"; break;
178 default: out.debug << "<unknown op>";
181 out.debug << " (" << node->getCompleteString() << ")";
188 bool TOutputTraverser::visitUnary(TVisit /* visit */, TIntermUnary* node)
190 TInfoSink& out = infoSink;
192 OutputTreeText(out, node, depth);
194 switch (node->getOp()) {
195 case EOpNegative: out.debug << "Negate value"; break;
196 case EOpVectorLogicalNot:
197 case EOpLogicalNot: out.debug << "Negate conditional"; break;
198 case EOpBitwiseNot: out.debug << "Bitwise not"; break;
200 case EOpPostIncrement: out.debug << "Post-Increment"; break;
201 case EOpPostDecrement: out.debug << "Post-Decrement"; break;
202 case EOpPreIncrement: out.debug << "Pre-Increment"; break;
203 case EOpPreDecrement: out.debug << "Pre-Decrement"; break;
205 case EOpConvIntToBool: out.debug << "Convert int to bool"; break;
206 case EOpConvUintToBool: out.debug << "Convert uint to bool"; break;
207 case EOpConvFloatToBool: out.debug << "Convert float to bool"; break;
208 case EOpConvDoubleToBool: out.debug << "Convert double to bool"; break;
209 case EOpConvIntToFloat: out.debug << "Convert int to float"; break;
210 case EOpConvUintToFloat: out.debug << "Convert uint to float"; break;
211 case EOpConvDoubleToFloat: out.debug << "Convert double to float"; break;
212 case EOpConvBoolToFloat: out.debug << "Convert bool to float"; break;
213 case EOpConvUintToInt: out.debug << "Convert uint to int"; break;
214 case EOpConvFloatToInt: out.debug << "Convert float to int"; break;
215 case EOpConvDoubleToInt: out.debug << "Convert double to int"; break;
216 case EOpConvBoolToInt: out.debug << "Convert bool to int"; break;
217 case EOpConvIntToUint: out.debug << "Convert int to uint"; break;
218 case EOpConvFloatToUint: out.debug << "Convert float to uint"; break;
219 case EOpConvDoubleToUint: out.debug << "Convert double to uint"; break;
220 case EOpConvBoolToUint: out.debug << "Convert bool to uint"; break;
221 case EOpConvIntToDouble: out.debug << "Convert int to double"; break;
222 case EOpConvUintToDouble: out.debug << "Convert uint to double"; break;
223 case EOpConvFloatToDouble: out.debug << "Convert float to double"; break;
224 case EOpConvBoolToDouble: out.debug << "Convert bool to double"; break;
226 case EOpRadians: out.debug << "radians"; break;
227 case EOpDegrees: out.debug << "degrees"; break;
228 case EOpSin: out.debug << "sine"; break;
229 case EOpCos: out.debug << "cosine"; break;
230 case EOpTan: out.debug << "tangent"; break;
231 case EOpAsin: out.debug << "arc sine"; break;
232 case EOpAcos: out.debug << "arc cosine"; break;
233 case EOpAtan: out.debug << "arc tangent"; break;
234 case EOpSinh: out.debug << "hyp. sine"; break;
235 case EOpCosh: out.debug << "hyp. cosine"; break;
236 case EOpTanh: out.debug << "hyp. tangent"; break;
237 case EOpAsinh: out.debug << "arc hyp. sine"; break;
238 case EOpAcosh: out.debug << "arc hyp. cosine"; break;
239 case EOpAtanh: out.debug << "arc hyp. tangent"; break;
241 case EOpExp: out.debug << "exp"; break;
242 case EOpLog: out.debug << "log"; break;
243 case EOpExp2: out.debug << "exp2"; break;
244 case EOpLog2: out.debug << "log2"; break;
245 case EOpSqrt: out.debug << "sqrt"; break;
246 case EOpInverseSqrt: out.debug << "inverse sqrt"; break;
248 case EOpAbs: out.debug << "Absolute value"; break;
249 case EOpSign: out.debug << "Sign"; break;
250 case EOpFloor: out.debug << "Floor"; break;
251 case EOpTrunc: out.debug << "trunc"; break;
252 case EOpRound: out.debug << "round"; break;
253 case EOpRoundEven: out.debug << "roundEven"; break;
254 case EOpCeil: out.debug << "Ceiling"; break;
255 case EOpFract: out.debug << "Fraction"; break;
257 case EOpIsNan: out.debug << "isnan"; break;
258 case EOpIsInf: out.debug << "isinf"; break;
260 case EOpFloatBitsToInt: out.debug << "floatBitsToInt"; break;
261 case EOpFloatBitsToUint:out.debug << "floatBitsToUint"; break;
262 case EOpIntBitsToFloat: out.debug << "intBitsToFloat"; break;
263 case EOpUintBitsToFloat:out.debug << "uintBitsToFloat"; break;
264 case EOpPackSnorm2x16: out.debug << "packSnorm2x16"; break;
265 case EOpUnpackSnorm2x16:out.debug << "unpackSnorm2x16"; break;
266 case EOpPackUnorm2x16: out.debug << "packUnorm2x16"; break;
267 case EOpUnpackUnorm2x16:out.debug << "unpackUnorm2x16"; break;
268 case EOpPackHalf2x16: out.debug << "packHalf2x16"; break;
269 case EOpUnpackHalf2x16: out.debug << "unpackHalf2x16"; break;
271 case EOpPackSnorm4x8: out.debug << "PackSnorm4x8"; break;
272 case EOpUnpackSnorm4x8: out.debug << "UnpackSnorm4x8"; break;
273 case EOpPackUnorm4x8: out.debug << "PackUnorm4x8"; break;
274 case EOpUnpackUnorm4x8: out.debug << "UnpackUnorm4x8"; break;
275 case EOpPackDouble2x32: out.debug << "PackDouble2x32"; break;
276 case EOpUnpackDouble2x32: out.debug << "UnpackDouble2x32"; break;
278 case EOpLength: out.debug << "length"; break;
279 case EOpNormalize: out.debug << "normalize"; break;
280 case EOpDPdx: out.debug << "dPdx"; break;
281 case EOpDPdy: out.debug << "dPdy"; break;
282 case EOpFwidth: out.debug << "fwidth"; break;
283 case EOpDPdxFine: out.debug << "dPdxFine"; break;
284 case EOpDPdyFine: out.debug << "dPdyFine"; break;
285 case EOpFwidthFine: out.debug << "fwidthFine"; break;
286 case EOpDPdxCoarse: out.debug << "dPdxCoarse"; break;
287 case EOpDPdyCoarse: out.debug << "dPdyCoarse"; break;
288 case EOpFwidthCoarse: out.debug << "fwidthCoarse"; break;
290 case EOpInterpolateAtCentroid: out.debug << "interpolateAtCentroid"; break;
292 case EOpDeterminant: out.debug << "determinant"; break;
293 case EOpMatrixInverse: out.debug << "inverse"; break;
294 case EOpTranspose: out.debug << "transpose"; break;
296 case EOpAny: out.debug << "any"; break;
297 case EOpAll: out.debug << "all"; break;
299 case EOpArrayLength: out.debug << "array length"; break;
301 case EOpEmitStreamVertex: out.debug << "EmitStreamVertex"; break;
302 case EOpEndStreamPrimitive: out.debug << "EndStreamPrimitive"; break;
304 case EOpAtomicCounterIncrement: out.debug << "AtomicCounterIncrement";break;
305 case EOpAtomicCounterDecrement: out.debug << "AtomicCounterDecrement";break;
306 case EOpAtomicCounter: out.debug << "AtomicCounter"; break;
308 case EOpTextureQuerySize: out.debug << "textureSize"; break;
309 case EOpTextureQueryLod: out.debug << "textureQueryLod"; break;
310 case EOpTextureQueryLevels: out.debug << "textureQueryLevels"; break;
311 case EOpTextureQuerySamples: out.debug << "textureSamples"; break;
312 case EOpImageQuerySize: out.debug << "imageQuerySize"; break;
313 case EOpImageQuerySamples: out.debug << "imageQuerySamples"; break;
314 case EOpImageLoad: out.debug << "imageLoad"; break;
316 case EOpBitFieldReverse: out.debug << "bitFieldReverse"; break;
317 case EOpBitCount: out.debug << "bitCount"; break;
318 case EOpFindLSB: out.debug << "findLSB"; break;
319 case EOpFindMSB: out.debug << "findMSB"; break;
321 case EOpNoise: out.debug << "noise"; break;
323 default: out.debug.message(EPrefixError, "Bad unary op");
326 out.debug << " (" << node->getCompleteString() << ")";
333 bool TOutputTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node)
335 TInfoSink& out = infoSink;
337 if (node->getOp() == EOpNull) {
338 out.debug.message(EPrefixError, "node is still EOpNull!");
342 OutputTreeText(out, node, depth);
344 switch (node->getOp()) {
345 case EOpSequence: out.debug << "Sequence\n"; return true;
346 case EOpLinkerObjects: out.debug << "Linker Objects\n"; return true;
347 case EOpComma: out.debug << "Comma"; break;
348 case EOpFunction: out.debug << "Function Definition: " << node->getName(); break;
349 case EOpFunctionCall: out.debug << "Function Call: " << node->getName(); break;
350 case EOpParameters: out.debug << "Function Parameters: "; break;
352 case EOpConstructFloat: out.debug << "Construct float"; break;
353 case EOpConstructDouble:out.debug << "Construct double"; break;
354 case EOpConstructVec2: out.debug << "Construct vec2"; break;
355 case EOpConstructVec3: out.debug << "Construct vec3"; break;
356 case EOpConstructVec4: out.debug << "Construct vec4"; break;
357 case EOpConstructBool: out.debug << "Construct bool"; break;
358 case EOpConstructBVec2: out.debug << "Construct bvec2"; break;
359 case EOpConstructBVec3: out.debug << "Construct bvec3"; break;
360 case EOpConstructBVec4: out.debug << "Construct bvec4"; break;
361 case EOpConstructInt: out.debug << "Construct int"; break;
362 case EOpConstructIVec2: out.debug << "Construct ivec2"; break;
363 case EOpConstructIVec3: out.debug << "Construct ivec3"; break;
364 case EOpConstructIVec4: out.debug << "Construct ivec4"; break;
365 case EOpConstructUint: out.debug << "Construct uint"; break;
366 case EOpConstructUVec2: out.debug << "Construct uvec2"; break;
367 case EOpConstructUVec3: out.debug << "Construct uvec3"; break;
368 case EOpConstructUVec4: out.debug << "Construct uvec4"; break;
369 case EOpConstructMat2x2: out.debug << "Construct mat2"; break;
370 case EOpConstructMat2x3: out.debug << "Construct mat2x3"; break;
371 case EOpConstructMat2x4: out.debug << "Construct mat2x4"; break;
372 case EOpConstructMat3x2: out.debug << "Construct mat3x2"; break;
373 case EOpConstructMat3x3: out.debug << "Construct mat3"; break;
374 case EOpConstructMat3x4: out.debug << "Construct mat3x4"; break;
375 case EOpConstructMat4x2: out.debug << "Construct mat4x2"; break;
376 case EOpConstructMat4x3: out.debug << "Construct mat4x3"; break;
377 case EOpConstructMat4x4: out.debug << "Construct mat4"; break;
378 case EOpConstructDMat2x2: out.debug << "Construct dmat2"; break;
379 case EOpConstructDMat2x3: out.debug << "Construct dmat2x3"; break;
380 case EOpConstructDMat2x4: out.debug << "Construct dmat2x4"; break;
381 case EOpConstructDMat3x2: out.debug << "Construct dmat3x2"; break;
382 case EOpConstructDMat3x3: out.debug << "Construct dmat3"; break;
383 case EOpConstructDMat3x4: out.debug << "Construct dmat3x4"; break;
384 case EOpConstructDMat4x2: out.debug << "Construct dmat4x2"; break;
385 case EOpConstructDMat4x3: out.debug << "Construct dmat4x3"; break;
386 case EOpConstructDMat4x4: out.debug << "Construct dmat4"; break;
387 case EOpConstructStruct: out.debug << "Construct structure"; break;
388 case EOpConstructTextureSampler: out.debug << "Construct combined texture-sampler"; break;
390 case EOpLessThan: out.debug << "Compare Less Than"; break;
391 case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
392 case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
393 case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
394 case EOpVectorEqual: out.debug << "Equal"; break;
395 case EOpVectorNotEqual: out.debug << "NotEqual"; break;
397 case EOpMod: out.debug << "mod"; break;
398 case EOpModf: out.debug << "modf"; break;
399 case EOpPow: out.debug << "pow"; break;
401 case EOpAtan: out.debug << "arc tangent"; break;
403 case EOpMin: out.debug << "min"; break;
404 case EOpMax: out.debug << "max"; break;
405 case EOpClamp: out.debug << "clamp"; break;
406 case EOpMix: out.debug << "mix"; break;
407 case EOpStep: out.debug << "step"; break;
408 case EOpSmoothStep: out.debug << "smoothstep"; break;
410 case EOpDistance: out.debug << "distance"; break;
411 case EOpDot: out.debug << "dot-product"; break;
412 case EOpCross: out.debug << "cross-product"; break;
413 case EOpFaceForward: out.debug << "face-forward"; break;
414 case EOpReflect: out.debug << "reflect"; break;
415 case EOpRefract: out.debug << "refract"; break;
416 case EOpMul: out.debug << "component-wise multiply"; break;
417 case EOpOuterProduct: out.debug << "outer product"; break;
419 case EOpEmitVertex: out.debug << "EmitVertex"; break;
420 case EOpEndPrimitive: out.debug << "EndPrimitive"; break;
422 case EOpBarrier: out.debug << "Barrier"; break;
423 case EOpMemoryBarrier: out.debug << "MemoryBarrier"; break;
424 case EOpMemoryBarrierAtomicCounter: out.debug << "MemoryBarrierAtomicCounter"; break;
425 case EOpMemoryBarrierBuffer: out.debug << "MemoryBarrierBuffer"; break;
426 case EOpMemoryBarrierImage: out.debug << "MemoryBarrierImage"; break;
427 case EOpMemoryBarrierShared: out.debug << "MemoryBarrierShared"; break;
428 case EOpGroupMemoryBarrier: out.debug << "GroupMemoryBarrier"; break;
430 case EOpAtomicAdd: out.debug << "AtomicAdd"; break;
431 case EOpAtomicMin: out.debug << "AtomicMin"; break;
432 case EOpAtomicMax: out.debug << "AtomicMax"; break;
433 case EOpAtomicAnd: out.debug << "AtomicAnd"; break;
434 case EOpAtomicOr: out.debug << "AtomicOr"; break;
435 case EOpAtomicXor: out.debug << "AtomicXor"; break;
436 case EOpAtomicExchange: out.debug << "AtomicExchange"; break;
437 case EOpAtomicCompSwap: out.debug << "AtomicCompSwap"; break;
439 case EOpImageQuerySize: out.debug << "imageQuerySize"; break;
440 case EOpImageQuerySamples: out.debug << "imageQuerySamples"; break;
441 case EOpImageLoad: out.debug << "imageLoad"; break;
442 case EOpImageStore: out.debug << "imageStore"; break;
443 case EOpImageAtomicAdd: out.debug << "imageAtomicAdd"; break;
444 case EOpImageAtomicMin: out.debug << "imageAtomicMin"; break;
445 case EOpImageAtomicMax: out.debug << "imageAtomicMax"; break;
446 case EOpImageAtomicAnd: out.debug << "imageAtomicAnd"; break;
447 case EOpImageAtomicOr: out.debug << "imageAtomicOr"; break;
448 case EOpImageAtomicXor: out.debug << "imageAtomicXor"; break;
449 case EOpImageAtomicExchange: out.debug << "imageAtomicExchange"; break;
450 case EOpImageAtomicCompSwap: out.debug << "imageAtomicCompSwap"; break;
452 case EOpTextureQuerySize: out.debug << "textureSize"; break;
453 case EOpTextureQueryLod: out.debug << "textureQueryLod"; break;
454 case EOpTextureQueryLevels: out.debug << "textureQueryLevels"; break;
455 case EOpTextureQuerySamples: out.debug << "textureSamples"; break;
456 case EOpTexture: out.debug << "texture"; break;
457 case EOpTextureProj: out.debug << "textureProj"; break;
458 case EOpTextureLod: out.debug << "textureLod"; break;
459 case EOpTextureOffset: out.debug << "textureOffset"; break;
460 case EOpTextureFetch: out.debug << "textureFetch"; break;
461 case EOpTextureFetchOffset: out.debug << "textureFetchOffset"; break;
462 case EOpTextureProjOffset: out.debug << "textureProjOffset"; break;
463 case EOpTextureLodOffset: out.debug << "textureLodOffset"; break;
464 case EOpTextureProjLod: out.debug << "textureProjLod"; break;
465 case EOpTextureProjLodOffset: out.debug << "textureProjLodOffset"; break;
466 case EOpTextureGrad: out.debug << "textureGrad"; break;
467 case EOpTextureGradOffset: out.debug << "textureGradOffset"; break;
468 case EOpTextureProjGrad: out.debug << "textureProjGrad"; break;
469 case EOpTextureProjGradOffset: out.debug << "textureProjGradOffset"; break;
470 case EOpTextureGather: out.debug << "textureGather"; break;
471 case EOpTextureGatherOffset: out.debug << "textureGatherOffset"; break;
472 case EOpTextureGatherOffsets: out.debug << "textureGatherOffsets"; break;
474 case EOpAddCarry: out.debug << "addCarry"; break;
475 case EOpSubBorrow: out.debug << "subBorrow"; break;
476 case EOpUMulExtended: out.debug << "uMulExtended"; break;
477 case EOpIMulExtended: out.debug << "iMulExtended"; break;
478 case EOpBitfieldExtract: out.debug << "bitfieldExtract"; break;
479 case EOpBitfieldInsert: out.debug << "bitfieldInsert"; break;
481 case EOpFma: out.debug << "fma"; break;
482 case EOpFrexp: out.debug << "frexp"; break;
483 case EOpLdexp: out.debug << "ldexp"; break;
485 case EOpInterpolateAtSample: out.debug << "interpolateAtSample"; break;
486 case EOpInterpolateAtOffset: out.debug << "interpolateAtOffset"; break;
488 default: out.debug.message(EPrefixError, "Bad aggregation op");
491 if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)
492 out.debug << " (" << node->getCompleteString() << ")";
499 bool TOutputTraverser::visitSelection(TVisit /* visit */, TIntermSelection* node)
501 TInfoSink& out = infoSink;
503 OutputTreeText(out, node, depth);
505 out.debug << "Test condition and select";
506 out.debug << " (" << node->getCompleteString() << ")\n";
510 OutputTreeText(out, node, depth);
511 out.debug << "Condition\n";
512 node->getCondition()->traverse(this);
514 OutputTreeText(out, node, depth);
515 if (node->getTrueBlock()) {
516 out.debug << "true case\n";
517 node->getTrueBlock()->traverse(this);
519 out.debug << "true case is null\n";
521 if (node->getFalseBlock()) {
522 OutputTreeText(out, node, depth);
523 out.debug << "false case\n";
524 node->getFalseBlock()->traverse(this);
532 static void OutputConstantUnion(TInfoSink& out, const TIntermTyped* node, const TConstUnionArray& constUnion, int depth)
534 int size = node->getType().computeNumComponents();
536 for (int i = 0; i < size; i++) {
537 OutputTreeText(out, node, depth);
538 switch (constUnion[i].getType()) {
540 if (constUnion[i].getBConst())
543 out.debug << "false";
545 out.debug << " (" << "const bool" << ")";
552 const double value = constUnion[i].getDConst();
553 // Print infinity in a portable way, for test stability.
554 // Other cases may be needed in the future: negative infinity,
556 if (is_positive_infinity(value))
557 out.debug << "inf\n";
559 const int maxSize = 300;
561 snprintf(buf, maxSize, "%f", value);
563 out.debug << buf << "\n";
569 const int maxSize = 300;
571 snprintf(buf, maxSize, "%d (%s)", constUnion[i].getIConst(), "const int");
573 out.debug << buf << "\n";
578 const int maxSize = 300;
580 snprintf(buf, maxSize, "%u (%s)", constUnion[i].getUConst(), "const uint");
582 out.debug << buf << "\n";
586 out.info.message(EPrefixInternalError, "Unknown constant", node->getLoc());
592 void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
594 OutputTreeText(infoSink, node, depth);
595 infoSink.debug << "Constant:\n";
597 OutputConstantUnion(infoSink, node, node->getConstArray(), depth + 1);
600 void TOutputTraverser::visitSymbol(TIntermSymbol* node)
602 OutputTreeText(infoSink, node, depth);
604 infoSink.debug << "'" << node->getName() << "' (" << node->getCompleteString() << ")\n";
606 if (! node->getConstArray().empty())
607 OutputConstantUnion(infoSink, node, node->getConstArray(), depth + 1);
610 bool TOutputTraverser::visitLoop(TVisit /* visit */, TIntermLoop* node)
612 TInfoSink& out = infoSink;
614 OutputTreeText(out, node, depth);
616 out.debug << "Loop with condition ";
617 if (! node->testFirst())
619 out.debug << "tested first\n";
623 OutputTreeText(infoSink, node, depth);
624 if (node->getTest()) {
625 out.debug << "Loop Condition\n";
626 node->getTest()->traverse(this);
628 out.debug << "No loop condition\n";
630 OutputTreeText(infoSink, node, depth);
631 if (node->getBody()) {
632 out.debug << "Loop Body\n";
633 node->getBody()->traverse(this);
635 out.debug << "No loop body\n";
637 if (node->getTerminal()) {
638 OutputTreeText(infoSink, node, depth);
639 out.debug << "Loop Terminal Expression\n";
640 node->getTerminal()->traverse(this);
648 bool TOutputTraverser::visitBranch(TVisit /* visit*/, TIntermBranch* node)
650 TInfoSink& out = infoSink;
652 OutputTreeText(out, node, depth);
654 switch (node->getFlowOp()) {
655 case EOpKill: out.debug << "Branch: Kill"; break;
656 case EOpBreak: out.debug << "Branch: Break"; break;
657 case EOpContinue: out.debug << "Branch: Continue"; break;
658 case EOpReturn: out.debug << "Branch: Return"; break;
659 case EOpCase: out.debug << "case: "; break;
660 case EOpDefault: out.debug << "default: "; break;
661 default: out.debug << "Branch: Unknown Branch"; break;
664 if (node->getExpression()) {
665 out.debug << " with expression\n";
667 node->getExpression()->traverse(this);
675 bool TOutputTraverser::visitSwitch(TVisit /* visit */, TIntermSwitch* node)
677 TInfoSink& out = infoSink;
679 OutputTreeText(out, node, depth);
680 out.debug << "switch\n";
682 OutputTreeText(out, node, depth);
683 out.debug << "condition\n";
685 node->getCondition()->traverse(this);
688 OutputTreeText(out, node, depth);
689 out.debug << "body\n";
691 node->getBody()->traverse(this);
699 // This function is the one to call externally to start the traversal.
700 // Individual functions can be initialized to 0 to skip processing of that
701 // type of node. It's children will still be processed.
703 void TIntermediate::output(TInfoSink& infoSink, bool tree)
705 infoSink.debug << "Shader version: " << version << "\n";
706 if (requestedExtensions.size() > 0) {
707 for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
708 infoSink.debug << "Requested " << *extIt << "\n";
712 infoSink.debug << "in xfb mode\n";
718 case EShLangTessControl:
719 infoSink.debug << "vertices = " << vertices << "\n";
722 case EShLangTessEvaluation:
723 infoSink.debug << "input primitive = " << TQualifier::getGeometryString(inputPrimitive) << "\n";
724 infoSink.debug << "vertex spacing = " << TQualifier::getVertexSpacingString(vertexSpacing) << "\n";
725 infoSink.debug << "triangle order = " << TQualifier::getVertexOrderString(vertexOrder) << "\n";
727 infoSink.debug << "using point mode\n";
730 case EShLangGeometry:
731 infoSink.debug << "invocations = " << invocations << "\n";
732 infoSink.debug << "max_vertices = " << vertices << "\n";
733 infoSink.debug << "input primitive = " << TQualifier::getGeometryString(inputPrimitive) << "\n";
734 infoSink.debug << "output primitive = " << TQualifier::getGeometryString(outputPrimitive) << "\n";
737 case EShLangFragment:
738 if (pixelCenterInteger)
739 infoSink.debug << "gl_FragCoord pixel center is integer\n";
741 infoSink.debug << "gl_FragCoord origin is upper left\n";
742 if (earlyFragmentTests)
743 infoSink.debug << "using early_fragment_tests\n";
744 if (depthLayout != EldNone)
745 infoSink.debug << "using " << TQualifier::getLayoutDepthString(depthLayout) << "\n";
746 if (blendEquations != 0) {
747 infoSink.debug << "using";
748 // blendEquations is a mask, decode it
749 for (TBlendEquationShift be = (TBlendEquationShift)0; be < EBlendCount; be = (TBlendEquationShift)(be + 1)) {
750 if (blendEquations & (1 << be))
751 infoSink.debug << " " << TQualifier::getBlendEquationString(be);
753 infoSink.debug << "\n";
758 infoSink.debug << "local_size = (" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << ")\n";
760 if (localSizeSpecId[0] != TQualifier::layoutNotSet ||
761 localSizeSpecId[1] != TQualifier::layoutNotSet ||
762 localSizeSpecId[2] != TQualifier::layoutNotSet) {
763 infoSink.debug << "local_size ids = (" <<
764 localSizeSpecId[0] << ", " <<
765 localSizeSpecId[1] << ", " <<
766 localSizeSpecId[2] << ")\n";
775 if (treeRoot == 0 || ! tree)
778 TOutputTraverser it(infoSink);
780 treeRoot->traverse(&it);
783 } // end namespace glslang