Add constant folding for length(), normalize(), fwidth(), dFdx(), and dFdy().
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21918 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
@@ -8,8 +8,11 @@ const float e = float(d); // 2.0
|
|||||||
const float f = e * float(c); // 6.0
|
const float f = e * float(c); // 6.0
|
||||||
const float g = f / float(d); // 3.0
|
const float g = f / float(d); // 3.0
|
||||||
|
|
||||||
|
const vec2 pytho = vec2(3.0, 4.0);
|
||||||
|
|
||||||
in vec4 inv;
|
in vec4 inv;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
out vec2 out2;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@@ -26,4 +29,5 @@ void main()
|
|||||||
vec4 arrayMax[int(max(float(array2.length()), float(array3.length())))];
|
vec4 arrayMax[int(max(float(array2.length()), float(array3.length())))];
|
||||||
vec4 arrayMin[int(min(float(array2.length()), float(array3.length())))];
|
vec4 arrayMin[int(min(float(array2.length()), float(array3.length())))];
|
||||||
FragColor = vec4(arrayMax.length(), arrayMin.length(), sin(3.14), cos(3.14)); // 3, 2, .00159, -.999
|
FragColor = vec4(arrayMax.length(), arrayMin.length(), sin(3.14), cos(3.14)); // 3, 2, .00159, -.999
|
||||||
|
out2 = length(pytho) + normalize(pytho) + dFdx(pytho) + dFdy(pytho) + fwidth(pytho); // 5+3/5, 5+4/5
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -377,12 +377,35 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
|
|||||||
case EOpDeterminant:
|
case EOpDeterminant:
|
||||||
case EOpAny:
|
case EOpAny:
|
||||||
case EOpAll:
|
case EOpAll:
|
||||||
|
case EOpLength:
|
||||||
newConstArray = new constUnion[1];
|
newConstArray = new constUnion[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
newConstArray = new constUnion[objectSize];
|
newConstArray = new constUnion[objectSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process non-component-wise operations
|
||||||
|
switch (op) {
|
||||||
|
case EOpLength:
|
||||||
|
case EOpNormalize:
|
||||||
|
{
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < objectSize; i++)
|
||||||
|
sum += double(unionArray[i].getFConst()) * unionArray[i].getFConst();
|
||||||
|
double length = sqrt(sum);
|
||||||
|
if (op == EOpLength)
|
||||||
|
newConstArray[0].setFConst(float(length));
|
||||||
|
else {
|
||||||
|
for (int i = 0; i < objectSize; i++)
|
||||||
|
newConstArray[i].setFConst(float(unionArray[i].getFConst() / length));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Functionality: constant folding: separate component-wise from non-component-wise
|
// TODO: Functionality: constant folding: separate component-wise from non-component-wise
|
||||||
for (int i = 0; i < objectSize; i++) {
|
for (int i = 0; i < objectSize; i++) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
@@ -433,6 +456,18 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
|
|||||||
newConstArray[i].setFConst(atan(unionArray[i].getFConst()));
|
newConstArray[i].setFConst(atan(unionArray[i].getFConst()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EOpLength:
|
||||||
|
case EOpNormalize:
|
||||||
|
// handled above as special case
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EOpDPdx:
|
||||||
|
case EOpDPdy:
|
||||||
|
case EOpFwidth:
|
||||||
|
// The derivatives are all mandated to create a constant 0.
|
||||||
|
newConstArray[i].setFConst(0.0f);
|
||||||
|
break;
|
||||||
|
|
||||||
// TODO: Functionality: constant folding: the rest of the ops have to be fleshed out
|
// TODO: Functionality: constant folding: the rest of the ops have to be fleshed out
|
||||||
|
|
||||||
case EOpExp:
|
case EOpExp:
|
||||||
@@ -465,13 +500,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
|
|||||||
case EOpPackHalf2x16:
|
case EOpPackHalf2x16:
|
||||||
case EOpUnpackHalf2x16:
|
case EOpUnpackHalf2x16:
|
||||||
|
|
||||||
case EOpLength:
|
|
||||||
|
|
||||||
case EOpDPdx:
|
|
||||||
case EOpDPdy:
|
|
||||||
case EOpFwidth:
|
|
||||||
// The derivatives are all mandated to create a constant 0.
|
|
||||||
|
|
||||||
case EOpDeterminant:
|
case EOpDeterminant:
|
||||||
case EOpMatrixInverse:
|
case EOpMatrixInverse:
|
||||||
case EOpTranspose:
|
case EOpTranspose:
|
||||||
@@ -480,7 +508,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
|
|||||||
case EOpAll:
|
case EOpAll:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine());
|
infoSink.info.message(EPrefixInternalError, "missing operator for unary constant folding", getLine());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -521,7 +549,6 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
|
|||||||
case EOpMix:
|
case EOpMix:
|
||||||
case EOpDistance:
|
case EOpDistance:
|
||||||
case EOpCross:
|
case EOpCross:
|
||||||
case EOpNormalize:
|
|
||||||
objectSize = children[0]->getAsConstantUnion()->getType().getObjectSize();
|
objectSize = children[0]->getAsConstantUnion()->getType().getObjectSize();
|
||||||
break;
|
break;
|
||||||
case EOpDot:
|
case EOpDot:
|
||||||
@@ -574,7 +601,6 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
|
|||||||
case EOpDistance:
|
case EOpDistance:
|
||||||
case EOpDot:
|
case EOpDot:
|
||||||
case EOpCross:
|
case EOpCross:
|
||||||
case EOpNormalize:
|
|
||||||
case EOpFaceForward:
|
case EOpFaceForward:
|
||||||
case EOpReflect:
|
case EOpReflect:
|
||||||
case EOpRefract:
|
case EOpRefract:
|
||||||
|
|||||||
Reference in New Issue
Block a user