summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-02-01 18:11:19 -0700
committerBrian <[email protected]>2007-02-01 18:11:19 -0700
commit9742547245f3dc4850faa9e83d178d17669d4c09 (patch)
tree02a435435b37caf6e5a070fdc65282208cc9b77a /src/mesa
parentabeca8d17d0728e68ec0c7cb9d9ca91b06b560d0 (diff)
Fix logic in _slang_simplify(): vec2() constructor case wasn't getting used.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c7
-rw-r--r--src/mesa/shader/slang/slang_simplify.c57
-rw-r--r--src/mesa/shader/slang/slang_simplify.h6
3 files changed, 47 insertions, 23 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index d09883c6645..ee1d6cbabc0 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1891,6 +1891,9 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper)
RETURN_ERROR2("Undefined variable:", varName, 0);
}
/* XXX make copy of this initializer? */
+
+ /* XXX try to simplify initializer here */foo
+
rhs = _slang_gen_operation(A, v->initializer);
assert(rhs);
init = new_node(IR_MOVE, var, rhs);
@@ -2649,7 +2652,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
lhs->Store = n->Store;
/* constant folding, etc */
- slang_simplify(var->initializer, &A->space, A->atoms);
+ _slang_simplify(var->initializer, &A->space, A->atoms);
rhs = _slang_gen_operation(A, var->initializer);
assert(rhs);
@@ -2703,7 +2706,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun)
assert(A->vartable);
/* fold constant expressions, etc. */
- slang_simplify(fun->body, &A->space, A->atoms);
+ _slang_simplify(fun->body, &A->space, A->atoms);
A->CurFunction = fun;
diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c
index 821a716f58c..c71313a7bb8 100644
--- a/src/mesa/shader/slang/slang_simplify.c
+++ b/src/mesa/shader/slang/slang_simplify.c
@@ -44,9 +44,9 @@
* declarations. I.e.: float foo[3 + 5];
*/
void
-slang_simplify(slang_operation *oper,
- const slang_assembly_name_space * space,
- slang_atom_pool * atoms)
+_slang_simplify(slang_operation *oper,
+ const slang_assembly_name_space * space,
+ slang_atom_pool * atoms)
{
GLboolean isFloat[4];
GLboolean isBool[4];
@@ -54,7 +54,7 @@ slang_simplify(slang_operation *oper,
/* first, simplify children */
for (i = 0; i < oper->num_children; i++) {
- slang_simplify(&oper->children[i], space, atoms);
+ _slang_simplify(&oper->children[i], space, atoms);
}
/* examine children */
@@ -75,7 +75,7 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
case slang_oper_subtract:
for (i = 0; i < 4; i++) {
oper->literal[i]
@@ -83,7 +83,7 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
case slang_oper_multiply:
for (i = 0; i < 4; i++) {
oper->literal[i]
@@ -91,7 +91,7 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
case slang_oper_divide:
for (i = 0; i < 4; i++) {
oper->literal[i]
@@ -99,12 +99,13 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
default:
; /* nothing */
}
}
- else if (n == 1 && isFloat[0]) {
+
+ if (n == 1 && isFloat[0]) {
switch (oper->type) {
case slang_oper_minus:
for (i = 0; i < 4; i++) {
@@ -112,17 +113,18 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
case slang_oper_plus:
COPY_4V(oper->literal, oper->children[0].literal);
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
- break;
+ return;
default:
; /* nothing */
}
}
- else if (n == 2 && isBool[0] && isBool[1]) {
+
+ if (n == 2 && isBool[0] && isBool[1]) {
/* simple boolean expression */
switch (oper->type) {
case slang_oper_logicaland:
@@ -133,7 +135,7 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
- break;
+ return;
case slang_oper_logicalor:
for (i = 0; i < 4; i++) {
const GLint a = oper->children[0].literal[i] ? 1 : 0;
@@ -142,7 +144,7 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
- break;
+ return;
case slang_oper_logicalxor:
for (i = 0; i < 4; i++) {
const GLint a = oper->children[0].literal[i] ? 1 : 0;
@@ -151,12 +153,13 @@ slang_simplify(slang_operation *oper,
}
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
- break;
+ return;
default:
; /* nothing */
}
}
- else if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
+
+ if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
/* vec4(flt, flt, flt, flt) constructor */
if (oper->type == slang_oper_call) {
if (strcmp((char *) oper->a_id, "vec4") == 0) {
@@ -166,19 +169,37 @@ slang_simplify(slang_operation *oper,
oper->literal[3] = oper->children[3].literal[0];
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
+ return;
}
}
}
- else if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
+
+ if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
/* vec3(flt, flt, flt) constructor */
if (oper->type == slang_oper_call) {
if (strcmp((char *) oper->a_id, "vec3") == 0) {
oper->literal[0] = oper->children[0].literal[0];
oper->literal[1] = oper->children[1].literal[0];
oper->literal[2] = oper->children[2].literal[0];
- oper->literal[3] = 0.0;
+ oper->literal[3] = oper->literal[2];
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
+ return;
+ }
+ }
+ }
+
+ if (n == 2 && isFloat[0] && isFloat[1]) {
+ /* vec4(flt, flt) constructor */
+ if (oper->type == slang_oper_call) {
+ if (strcmp((char *) oper->a_id, "vec2") == 0) {
+ oper->literal[0] = oper->children[0].literal[0];
+ oper->literal[1] = oper->children[1].literal[0];
+ oper->literal[2] = oper->literal[1];
+ oper->literal[3] = oper->literal[1];
+ slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */
+ oper->type = slang_oper_literal_float;
+ return;
}
}
}
diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h
index 0ca1fa2f0d2..5ff7292f0fb 100644
--- a/src/mesa/shader/slang/slang_simplify.h
+++ b/src/mesa/shader/slang/slang_simplify.h
@@ -3,9 +3,9 @@
#define SLANG_SIMPLIFY_H
extern void
-slang_simplify(slang_operation *oper,
- const slang_assembly_name_space * space,
- slang_atom_pool * atoms);
+_slang_simplify(slang_operation *oper,
+ const slang_assembly_name_space * space,
+ slang_atom_pool * atoms);
extern GLboolean