Permalink
Browse files

make unop constant folding work on floats as well, plus tests

  • Loading branch information...
1 parent 919ceb4 commit b59797be39913d06d600196ccb1f7a3f2dadf59f @aras-p committed Jan 31, 2013
@@ -87,17 +87,24 @@ TIntermConstant* FoldUnaryConstantExpression(TOperator op, TIntermConstant* node
if (!node)
return NULL;
- // for now, only support integers; we really only need constant folding for array sizes
- if (node->getBasicType() != EbtInt)
+ // for now, only support integers and floats
+ if (node->getBasicType() != EbtInt && node->getBasicType() != EbtFloat)
return NULL;
-
TIntermConstant* newNode = new TIntermConstant(node->getType());
switch (op)
{
case EOpNegative:
- for (unsigned i = 0; i < newNode->getCount(); ++i)
- newNode->setValue(i, -node->getValue(i).asInt);
+ if (node->getBasicType() == EbtInt)
+ {
+ for (unsigned i = 0; i < newNode->getCount(); ++i)
+ newNode->setValue(i, -node->getValue(i).asInt);
+ }
+ else
+ {
+ for (unsigned i = 0; i < newNode->getCount(); ++i)
+ newNode->setValue(i, -node->getValue(i).asFloat);
+ }
break;
default:
delete newNode;
@@ -5,11 +5,14 @@ static int kInt3 = 11;
float size1 = 512.0;
float size2 = 1.0 / 512.0;
float size3 = kInt1;
-//float size4 = kInt2 / 3.0;
-//float size5 = 5 + kInt3;
-//float size6 = kInt2 * 512.0;
+float size4 = kInt2 / 3.0;
+float size5 = 5 - kInt2;
+float size6 = kInt2 * 512.0;
+float size7 = -kInt1;
+float size8 = -(1.0 / 4.0 + (4.0 * (-(2.0/4.0))));
+float size9 = -(1.0 / 4 + (4.0 * (-(2/4))));
float4 main() : POSITION
{
- return float4(kInt1, kInt2, kInt3, size2);
+ return float4(kInt1, kInt2, kInt3, size2 + size8);
}
@@ -7,11 +7,18 @@ uniform float size1 = 512.0;
uniform float size2 = 0.00195313;
#line 7
uniform float size3 = 3.0;
-#line 12
+uniform float size4 = 2.33333;
+uniform float size5 = -2.0;
+uniform float size6 = 3584.0;
+#line 11
+uniform float size7 = -3.0;
+uniform float size8 = 1.75;
+uniform float size9 = -0.25;
+#line 15
vec4 xlat_main( );
-#line 12
+#line 15
vec4 xlat_main( ) {
- return vec4( 3.0, 7.0, float(kInt3), size2);
+ return vec4( 3.0, 7.0, float(kInt3), (size2 + size8));
}
void main() {
vec4 xl_retval;
@@ -21,3 +28,4 @@ void main() {
// uniforms:
// size2:<none> type 9 arrsize 0
+// size8:<none> type 9 arrsize 0
@@ -7,11 +7,18 @@ uniform float size1 = 512.0;
uniform float size2 = 0.00195313;
#line 7
uniform float size3 = 3.0;
-#line 12
+uniform float size4 = 2.33333;
+uniform float size5 = -2.0;
+uniform float size6 = 3584.0;
+#line 11
+uniform float size7 = -3.0;
+uniform float size8 = 1.75;
+uniform float size9 = -0.25;
+#line 15
vec4 xlat_main( );
-#line 12
+#line 15
vec4 xlat_main( ) {
- return vec4( 3.0, 7.0, float(kInt3), size2);
+ return vec4( 3.0, 7.0, float(kInt3), (size2 + size8));
}
void main() {
vec4 xl_retval;
@@ -21,3 +28,4 @@ void main() {
// uniforms:
// size2:<none> type 9 arrsize 0
+// size8:<none> type 9 arrsize 0
@@ -5,11 +5,14 @@ static int kInt3 = 11;
float size1 = 512.0;
float size2 = 1.0 / 512.0;
float size3 = kInt1;
-//float size4 = kInt2 / 3.0;
-//float size5 = 5 + kInt3;
-//float size6 = kInt2 * 512.0;
+float size4 = kInt2 / 3.0;
+float size5 = 5 - kInt2;
+float size6 = kInt2 * 512.0;
+float size7 = -kInt1;
+float size8 = -(1.0 / 4.0 + (4.0 * (-(2.0/4.0))));
+float size9 = -(1.0 / 4 + (4.0 * (-(2/4))));
float4 main() : POSITION
{
- return float4(kInt1, kInt2, kInt3, size2);
+ return float4(kInt1, kInt2, kInt3, size2 + size8);
}
@@ -6,11 +6,18 @@ uniform float size1;
uniform float size2;
#line 7
uniform float size3;
-#line 12
+uniform float size4;
+uniform float size5;
+uniform float size6;
+#line 11
+uniform float size7;
+uniform float size8;
+uniform float size9;
+#line 15
vec4 xlat_main( );
-#line 12
+#line 15
vec4 xlat_main( ) {
- return vec4( 3.0, 7.0, float(kInt3), size2);
+ return vec4( 3.0, 7.0, float(kInt3), (size2 + size8));
}
void main() {
vec4 xl_retval;
@@ -20,3 +27,4 @@ void main() {
// uniforms:
// size2:<none> type 9 arrsize 0
+// size8:<none> type 9 arrsize 0
@@ -6,11 +6,18 @@ uniform highp float size1;
uniform highp float size2;
#line 7
uniform highp float size3;
-#line 12
+uniform highp float size4;
+uniform highp float size5;
+uniform highp float size6;
+#line 11
+uniform highp float size7;
+uniform highp float size8;
+uniform highp float size9;
+#line 15
highp vec4 xlat_main( );
-#line 12
+#line 15
highp vec4 xlat_main( ) {
- return vec4( 3.0, 7.0, float(kInt3), size2);
+ return vec4( 3.0, 7.0, float(kInt3), (size2 + size8));
}
void main() {
highp vec4 xl_retval;
@@ -20,3 +27,4 @@ void main() {
// uniforms:
// size2:<none> type 9 arrsize 0
+// size8:<none> type 9 arrsize 0

0 comments on commit b59797b

Please sign in to comment.