Only initialize through a temporary variable if the same symbol name is used in…

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
parent b6ef8f11
......@@ -144,6 +144,8 @@
'compiler/TranslatorHLSL.h',
'compiler/UnfoldSelect.cpp',
'compiler/UnfoldSelect.h',
'compiler/SearchSymbol.cpp',
'compiler/SearchSymbol.h',
],
},
],
......
......@@ -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 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
// 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;
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SearchSymbol is an AST traverser to detect the use of a given symbol name
//
#include "compiler/SearchSymbol.h"
#include "compiler/InfoSink.h"
#include "compiler/OutputHLSL.h"
namespace sh
{
SearchSymbol::SearchSymbol(const TString &symbol) : mSymbol(symbol)
{
match = false;
}
void SearchSymbol::traverse(TIntermNode *node)
{
node->traverse(this);
}
void SearchSymbol::visitSymbol(TIntermSymbol *symbolNode)
{
if (symbolNode->getSymbol() == mSymbol)
{
match = true;
}
}
bool SearchSymbol::foundMatch() const
{
return match;
}
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SearchSymbol is an AST traverser to detect the use of a given symbol name
//
#ifndef COMPILER_SEARCHSYMBOL_H_
#define COMPILER_SEARCHSYMBOL_H_
#include "compiler/intermediate.h"
#include "compiler/ParseHelper.h"
namespace sh
{
class SearchSymbol : public TIntermTraverser
{
public:
SearchSymbol(const TString &symbol);
void traverse(TIntermNode *node);
void visitSymbol(TIntermSymbol *symbolNode);
bool foundMatch() const;
protected:
const TString &mSymbol;
bool match;
};
}
#endif // COMPILER_SEARCHSYMBOL_H_
......@@ -3,6 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// UnfoldSelect is an AST traverser to output the select operator ?: as if-else statements
//
#include "compiler/UnfoldSelect.h"
......
......@@ -3,6 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// UnfoldSelect is an AST traverser to output the select operator ?: as if-else statements
//
#ifndef COMPILER_UNFOLDSELECT_H_
#define COMPILER_UNFOLDSELECT_H_
......
......@@ -160,6 +160,10 @@
>
</File>
<File
RelativePath=".\SearchSymbol.cpp"
>
</File>
<File
RelativePath=".\TranslatorHLSL.cpp"
>
</File>
......@@ -178,6 +182,10 @@
>
</File>
<File
RelativePath=".\SearchSymbol.h"
>
</File>
<File
RelativePath=".\TranslatorHLSL.h"
>
</File>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment