diff options
author | Ben Murdoch <benm@google.com> | 2011-05-16 16:25:10 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-23 18:54:14 +0100 |
commit | ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb (patch) | |
tree | db769fadd053248f85db67434a5b275224defef7 /Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp | |
parent | 52e2557aeb8477967e97fd24f20f8f407a10fa15 (diff) | |
download | external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.zip external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.gz external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.bz2 |
Merge WebKit at r76408: Initial merge by git.
Change-Id: I5b91decbd693ccbf5c1b8354b37cd68cc9a1ea53
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp')
-rw-r--r-- | Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp b/Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp index 8b8a4e6..57e99d2 100644 --- a/Source/ThirdParty/ANGLE/src/compiler/OutputHLSL.cpp +++ b/Source/ThirdParty/ANGLE/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> @@ -64,7 +65,7 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr mScopeDepth = 0; - mArgumentIndex = 0; + mUniqueIndex = 0; } OutputHLSL::~OutputHLSL() @@ -96,7 +97,7 @@ int OutputHLSL::vectorSize(const TType &type) const void OutputHLSL::header() { - EShLanguage language = mContext.language; + ShShaderType shaderType = mContext.shaderType; TInfoSinkBase &out = mHeader; for (StructDeclarations::iterator structDeclaration = mStructDeclarations.begin(); structDeclaration != mStructDeclarations.end(); structDeclaration++) @@ -109,7 +110,7 @@ void OutputHLSL::header() out << *constructor; } - if (language == EShLangFragment) + if (shaderType == SH_FRAGMENT_SHADER) { TString uniforms; TString varyings; @@ -361,7 +362,8 @@ void OutputHLSL::header() " float diff;\n" "};\n" "\n" - "uniform gl_DepthRangeParameters gl_DepthRange;\n" + "uniform float3 dx_DepthRange;" + "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n" "\n"; } @@ -653,7 +655,39 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) switch (node->getOp()) { case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break; - case EOpInitialize: outputTriplet(visit, "", " = ", ""); break; + case EOpInitialize: + if (visit == PreVisit) + { + // GLSL allows to write things like "float x = x;" where a new variable x is defined + // and the value of an existing variable x is assigned. HLSL uses C semantics (the + // new variable is created before the assignment is evaluated), so we need to convert + // this to "float t = x, x = t;". + + TIntermSymbol *symbolNode = node->getLeft()->getAsSymbolNode(); + TIntermTyped *expression = node->getRight(); + + sh::SearchSymbol searchSymbol(symbolNode->getSymbol()); + expression->traverse(&searchSymbol); + bool sameSymbol = searchSymbol.foundMatch(); + + 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; case EOpSubAssign: outputTriplet(visit, "(", " -= ", ")"); break; case EOpMulAssign: outputTriplet(visit, "(", " *= ", ")"); break; @@ -933,9 +967,9 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node) case EOpFract: outputTriplet(visit, "frac(", "", ")"); break; case EOpLength: outputTriplet(visit, "length(", "", ")"); break; case EOpNormalize: outputTriplet(visit, "normalize(", "", ")"); break; -// case EOpDPdx: outputTriplet(visit, "ddx(", "", ")"); break; -// case EOpDPdy: outputTriplet(visit, "ddy(", "", ")"); break; -// case EOpFwidth: outputTriplet(visit, "fwidth(", "", ")"); break; + case EOpDFdx: outputTriplet(visit, "ddx(", "", ")"); break; + case EOpDFdy: outputTriplet(visit, "ddy(", "", ")"); break; + case EOpFwidth: outputTriplet(visit, "fwidth(", "", ")"); break; case EOpAny: outputTriplet(visit, "any(", "", ")"); break; case EOpAll: outputTriplet(visit, "all(", "", ")"); break; default: UNREACHABLE(); @@ -946,7 +980,7 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node) bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) { - EShLanguage language = mContext.language; + ShShaderType shaderType = mContext.shaderType; TInfoSinkBase &out = mBody; switch (node->getOp()) @@ -1392,7 +1426,7 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) TInfoSinkBase &out = mBody; - if (!node->testFirst()) + if (node->getType() == ELoopDoWhile) { out << "do\n" "{\n"; @@ -1404,14 +1438,14 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) mUnfoldSelect->traverse(node->getInit()); } - if (node->getTest()) + if (node->getCondition()) { - mUnfoldSelect->traverse(node->getTest()); + mUnfoldSelect->traverse(node->getCondition()); } - if (node->getTerminal()) + if (node->getExpression()) { - mUnfoldSelect->traverse(node->getTerminal()); + mUnfoldSelect->traverse(node->getExpression()); } out << "for("; @@ -1423,16 +1457,16 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) out << "; "; - if (node->getTest()) + if (node->getCondition()) { - node->getTest()->traverse(this); + node->getCondition()->traverse(this); } out << "; "; - if (node->getTerminal()) + if (node->getExpression()) { - node->getTerminal()->traverse(this); + node->getExpression()->traverse(this); } out << ")\n" @@ -1446,11 +1480,11 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) out << "}\n"; - if (!node->testFirst()) + if (node->getType() == ELoopDoWhile) { out << "while(\n"; - node->getTest()->traverse(this); + node->getCondition()->traverse(this); out << ")"; } @@ -1565,9 +1599,9 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) } // Parse comparator and limit value - if (index != NULL && node->getTest()) + if (index != NULL && node->getCondition()) { - TIntermBinary *test = node->getTest()->getAsBinaryNode(); + TIntermBinary *test = node->getCondition()->getAsBinaryNode(); if (test && test->getLeft()->getAsSymbolNode()->getId() == index->getId()) { @@ -1585,10 +1619,10 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) } // Parse increment - if (index != NULL && comparator != EOpNull && node->getTerminal()) + if (index != NULL && comparator != EOpNull && node->getExpression()) { - TIntermBinary *binaryTerminal = node->getTerminal()->getAsBinaryNode(); - TIntermUnary *unaryTerminal = node->getTerminal()->getAsUnaryNode(); + TIntermBinary *binaryTerminal = node->getExpression()->getAsBinaryNode(); + TIntermUnary *unaryTerminal = node->getExpression()->getAsUnaryNode(); if (binaryTerminal) { @@ -1711,7 +1745,7 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol) if (name.empty()) // HLSL demands named arguments, also for prototypes { - name = "x" + str(mArgumentIndex++); + name = "x" + str(mUniqueIndex++); } else { |