Only output DepthRange, xor() and mod() when used

TRAC #11736 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@281 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c6977ce5
...@@ -34,6 +34,12 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr ...@@ -34,6 +34,12 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr
mUsesTexture2DProj_bias = false; mUsesTexture2DProj_bias = false;
mUsesTextureCube = false; mUsesTextureCube = false;
mUsesTextureCube_bias = false; mUsesTextureCube_bias = false;
mUsesDepthRange = false;
mUsesXor = false;
mUsesMod1 = false;
mUsesMod2 = false;
mUsesMod3 = false;
mUsesMod4 = false;
mUsesFaceforward1 = false; mUsesFaceforward1 = false;
mUsesFaceforward2 = false; mUsesFaceforward2 = false;
mUsesFaceforward3 = false; mUsesFaceforward3 = false;
...@@ -476,40 +482,63 @@ void OutputHLSL::header() ...@@ -476,40 +482,63 @@ void OutputHLSL::header()
out << "\n"; out << "\n";
} }
out << "struct gl_DepthRangeParameters\n" if (mUsesDepthRange)
"{\n" {
" float near;\n" out << "struct gl_DepthRangeParameters\n"
" float far;\n" "{\n"
" float diff;\n" " float near;\n"
"};\n" " float far;\n"
"\n" " float diff;\n"
"uniform gl_DepthRangeParameters gl_DepthRange;\n" "};\n"
"\n" "\n"
"bool xor(bool p, bool q)\n" "uniform gl_DepthRangeParameters gl_DepthRange;\n"
"{\n" "\n";
" return (p || q) && !(p && q);\n" }
"}\n"
"\n" if (mUsesXor)
"float mod(float x, float y)\n" {
"{\n" out << "bool xor(bool p, bool q)\n"
" return x - y * floor(x / y);\n" "{\n"
"}\n" " return (p || q) && !(p && q);\n"
"\n" "}\n"
"float2 mod(float2 x, float y)\n" "\n";
"{\n" }
" return x - y * floor(x / y);\n"
"}\n" if (mUsesMod1)
"\n" {
"float3 mod(float3 x, float y)\n" out << "float mod(float x, float y)\n"
"{\n" "{\n"
" return x - y * floor(x / y);\n" " return x - y * floor(x / y);\n"
"}\n" "}\n"
"\n" "\n";
"float4 mod(float4 x, float y)\n" }
"{\n"
" return x - y * floor(x / y);\n" if (mUsesMod2)
"}\n" {
"\n"; out << "float2 mod(float2 x, float y)\n"
"{\n"
" return x - y * floor(x / y);\n"
"}\n"
"\n";
}
if (mUsesMod3)
{
out << "float3 mod(float3 x, float y)\n"
"{\n"
" return x - y * floor(x / y);\n"
"}\n"
"\n";
}
if (mUsesMod4)
{
out << "float4 mod(float4 x, float y)\n"
"{\n"
" return x - y * floor(x / y);\n"
"}\n"
"\n";
}
if (mUsesFaceforward1) if (mUsesFaceforward1)
{ {
...@@ -812,6 +841,11 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -812,6 +841,11 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
{ {
out << "gl_Color"; out << "gl_Color";
} }
else if (name == "gl_DepthRange")
{
mUsesDepthRange = true;
out << name;
}
else else
{ {
TQualifier qualifier = node->getQualifier(); TQualifier qualifier = node->getQualifier();
...@@ -1042,7 +1076,10 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1042,7 +1076,10 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break; case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break;
case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break; case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break;
case EOpLogicalOr: outputTriplet(visit, "(", " || ", ")"); break; case EOpLogicalOr: outputTriplet(visit, "(", " || ", ")"); break;
case EOpLogicalXor: outputTriplet(visit, "xor(", ", ", ")"); break; case EOpLogicalXor:
mUsesXor = true;
outputTriplet(visit, "xor(", ", ", ")");
break;
case EOpLogicalAnd: outputTriplet(visit, "(", " && ", ")"); break; case EOpLogicalAnd: outputTriplet(visit, "(", " && ", ")"); break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1457,7 +1494,20 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1457,7 +1494,20 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break; case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
case EOpVectorEqual: outputTriplet(visit, "(", " == ", ")"); break; case EOpVectorEqual: outputTriplet(visit, "(", " == ", ")"); break;
case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break; case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break;
case EOpMod: outputTriplet(visit, "mod(", ", ", ")"); break; case EOpMod:
{
switch (node->getSequence()[0]->getAsTyped()->getSize()) // Number of components in the first argument
{
case 1: mUsesMod1 = true; break;
case 2: mUsesMod2 = true; break;
case 3: mUsesMod3 = true; break;
case 4: mUsesMod4 = true; break;
default: UNREACHABLE();
}
outputTriplet(visit, "mod(", ", ", ")");
}
break;
case EOpPow: outputTriplet(visit, "pow(", ", ", ")"); break; case EOpPow: outputTriplet(visit, "pow(", ", ", ")"); break;
case EOpAtan: case EOpAtan:
ASSERT(node->getSequence().size() == 2); // atan(x) is a unary operator ASSERT(node->getSequence().size() == 2); // atan(x) is a unary operator
......
...@@ -73,6 +73,12 @@ class OutputHLSL : public TIntermTraverser ...@@ -73,6 +73,12 @@ class OutputHLSL : public TIntermTraverser
bool mUsesTexture2DProj_bias; bool mUsesTexture2DProj_bias;
bool mUsesTextureCube; bool mUsesTextureCube;
bool mUsesTextureCube_bias; bool mUsesTextureCube_bias;
bool mUsesDepthRange;
bool mUsesXor;
bool mUsesMod1;
bool mUsesMod2;
bool mUsesMod3;
bool mUsesMod4;
bool mUsesFaceforward1; bool mUsesFaceforward1;
bool mUsesFaceforward2; bool mUsesFaceforward2;
bool mUsesFaceforward3; bool mUsesFaceforward3;
......
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