Only initialize through a temporary variable if the same symbol name is used in the initialization expression.
TRAC #13627
The previous patch can generate a lot of unnecessary temporary variables. By first checking whether the same symbol name is reused the clutter is reduced to an absolute minimum (typical shaders won't rely on this odd GLSL semantic behavior so the workaround is hardly ever needed).
Signed-off-by: Daniel Koch
Author: Nicolas Capens
git-svn-id: https://angleproject.googlecode.com/svn/trunk@479 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index e306552..77ea944 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -9,6 +9,7 @@
#include "compiler/debug.h"
#include "compiler/InfoSink.h"
#include "compiler/UnfoldSelect.h"
+#include "compiler/SearchSymbol.h"
#include <stdio.h>
#include <algorithm>
@@ -661,16 +662,29 @@
// new variable is created before the assignment is evaluated), so we need to convert
// this to "float t = x, x = t;".
- // Type already printed
- out << "t" + str(mUniqueIndex) + " = ";
- node->getRight()->traverse(this);
- out << ", ";
- node->getLeft()->traverse(this);
- out << " = t" + str(mUniqueIndex);
+ TIntermSymbol *symbolNode = node->getLeft()->getAsSymbolNode();
+ TIntermTyped *expression = node->getRight();
- mUniqueIndex++;
+ sh::SearchSymbol searchSymbol(symbolNode->getSymbol());
+ expression->traverse(&searchSymbol);
+ bool sameSymbol = searchSymbol.foundMatch();
- return false;
+ if (sameSymbol)
+ {
+ // Type already printed
+ out << "t" + str(mUniqueIndex) + " = ";
+ expression->traverse(this);
+ out << ", ";
+ symbolNode->traverse(this);
+ out << " = t" + str(mUniqueIndex);
+
+ mUniqueIndex++;
+ return false;
+ }
+ }
+ else if (visit == InVisit)
+ {
+ out << " = ";
}
break;
case EOpAddAssign: outputTriplet(visit, "(", " += ", ")"); break;