diff options
author | Brian <[email protected]> | 2007-02-03 17:24:24 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-02-03 17:24:24 -0700 |
commit | 93b975a1d9fcc4a10987676f7368809522f27d71 (patch) | |
tree | ebf408cfd8fbca10dea39eb594346e4fe03636b9 /src | |
parent | 5ee684cba9b1f63090e184125e5890da4fc1d28c (diff) |
Add literal_size field to slang_operation.
Used to track the number of components in a float/int/bool literal.
Helps with some typechecking things.
Fixes problems with calls such as "distance(v2, vec2(1.0, 2.0))"
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 14 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 3 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_operation.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_operation.h | 1 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_simplify.c | 30 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_typeinfo.c | 45 |
6 files changed, 85 insertions, 10 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 4cb161a5b65..6b7df0597b6 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1040,7 +1040,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, static slang_ir_node * _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, - slang_operation *oper, slang_operation *dest) + slang_operation *oper, slang_operation *dest) { slang_ir_node *n; slang_operation *inlined; @@ -1694,6 +1694,7 @@ _slang_gen_logical_and(slang_assemble_ctx *A, slang_operation *oper) slang_operation_copy(&select->children[1], &oper->children[1]); select->children[2].type = slang_oper_literal_bool; ASSIGN_4V(select->children[2].literal, 0, 0, 0, 0); + select->children[2].literal_size = 2; n = _slang_gen_select(A, select); @@ -1724,6 +1725,7 @@ _slang_gen_logical_or(slang_assemble_ctx *A, slang_operation *oper) select->children[1].type = slang_oper_literal_bool; ASSIGN_4V(select->children[2].literal, 1, 1, 1, 1); slang_operation_copy(&select->children[2], &oper->children[1]); + select->children[2].literal_size = 2; n = _slang_gen_select(A, select); @@ -1867,9 +1869,19 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) if (!var) { RETURN_ERROR2("Undefined variable:", varName, 0); } +#if 0 /* XXX make copy of this initializer? */ + { + slang_operation dup; + slang_operation_construct(&dup); + slang_operation_copy(&dup, v->initializer); + _slang_simplify(&dup, &A->space, A->atoms); + rhs = _slang_gen_operation(A, &dup); + } +#else _slang_simplify(v->initializer, &A->space, A->atoms); rhs = _slang_gen_operation(A, v->initializer); +#endif assert(rhs); init = new_node(IR_MOVE, var, rhs); /* diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 619fe50ce53..199f96e441e 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -1029,6 +1029,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal[1] = op->literal[2] = op->literal[3] = (GLfloat) number; + op->literal_size = 1; break; case OP_PUSH_INT: op->type = slang_oper_literal_int; @@ -1038,6 +1039,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal[1] = op->literal[2] = op->literal[3] = (GLfloat) number; + op->literal_size = 1; break; case OP_PUSH_FLOAT: op->type = slang_oper_literal_float; @@ -1046,6 +1048,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal[1] = op->literal[2] = op->literal[3] = op->literal[0]; + op->literal_size = 1; break; case OP_PUSH_IDENTIFIER: op->type = slang_oper_identifier; diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c index c16ec7f8079..51a64ca30ba 100644 --- a/src/mesa/shader/slang/slang_compile_operation.c +++ b/src/mesa/shader/slang/slang_compile_operation.c @@ -60,6 +60,7 @@ slang_operation_destruct(slang_operation * oper) for (i = 0; i < oper->num_children; i++) slang_operation_destruct(oper->children + i); slang_alloc_free(oper->children); + /*#define FREE_MEMORY*/ #ifdef FREE_MEMORY /* XXX revisit and fix memory coruption here ! */ slang_variable_scope_destruct(oper->locals); @@ -106,6 +107,7 @@ slang_operation_copy(slang_operation * x, const slang_operation * y) z.literal[1] = y->literal[1]; z.literal[2] = y->literal[2]; z.literal[3] = y->literal[3]; + z.literal_size = y->literal_size; z.a_id = y->a_id; if (y->locals) { if (!slang_variable_scope_copy(z.locals, y->locals)) { diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h index 121b5832eff..3f5b1bb8f39 100644 --- a/src/mesa/shader/slang/slang_compile_operation.h +++ b/src/mesa/shader/slang/slang_compile_operation.h @@ -117,6 +117,7 @@ typedef struct slang_operation_ struct slang_operation_ *children; GLuint num_children; GLfloat literal[4]; /**< Used for float, int and bool values */ + GLuint literal_size; /**< 1, 2, 3, or 4 */ slang_atom a_id; /**< type: asm, identifier, call, field */ slang_variable_scope *locals; /**< local vars for scope */ struct slang_function_ *fun; /**< If type == slang_oper_call */ diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index ef8b2fedd80..0e433281e8b 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -123,7 +123,7 @@ _slang_simplify(slang_operation *oper, isBool[i] = (oper->children[i].type == slang_oper_literal_bool); } - if (n == 2 && isFloat[0] && isFloat[1]) { + if (oper->num_children == 2 && isFloat[0] && isFloat[1]) { /* probably simple arithmetic */ switch (oper->type) { case slang_oper_add: @@ -131,6 +131,7 @@ _slang_simplify(slang_operation *oper, oper->literal[i] = oper->children[0].literal[i] + oper->children[1].literal[i]; } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -139,6 +140,7 @@ _slang_simplify(slang_operation *oper, oper->literal[i] = oper->children[0].literal[i] - oper->children[1].literal[i]; } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -147,6 +149,7 @@ _slang_simplify(slang_operation *oper, oper->literal[i] = oper->children[0].literal[i] * oper->children[1].literal[i]; } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -155,6 +158,7 @@ _slang_simplify(slang_operation *oper, oper->literal[i] = oper->children[0].literal[i] / oper->children[1].literal[i]; } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -163,17 +167,19 @@ _slang_simplify(slang_operation *oper, } } - if (n == 1 && isFloat[0]) { + if (oper->num_children == 1 && isFloat[0]) { switch (oper->type) { case slang_oper_minus: for (i = 0; i < 4; i++) { oper->literal[i] = -oper->children[0].literal[i]; } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; case slang_oper_plus: COPY_4V(oper->literal, oper->children[0].literal); + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -182,7 +188,7 @@ _slang_simplify(slang_operation *oper, } } - if (n == 2 && isBool[0] && isBool[1]) { + if (oper->num_children == 2 && isBool[0] && isBool[1]) { /* simple boolean expression */ switch (oper->type) { case slang_oper_logicaland: @@ -191,6 +197,7 @@ _slang_simplify(slang_operation *oper, const GLint b = oper->children[1].literal[i] ? 1 : 0; oper->literal[i] = (GLfloat) (a && b); } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_bool; return; @@ -200,6 +207,7 @@ _slang_simplify(slang_operation *oper, const GLint b = oper->children[1].literal[i] ? 1 : 0; oper->literal[i] = (GLfloat) (a || b); } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_bool; return; @@ -209,6 +217,7 @@ _slang_simplify(slang_operation *oper, const GLint b = oper->children[1].literal[i] ? 1 : 0; oper->literal[i] = (GLfloat) (a ^ b); } + oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); oper->type = slang_oper_literal_bool; return; @@ -217,7 +226,8 @@ _slang_simplify(slang_operation *oper, } } - if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) { + if (oper->num_children == 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) { @@ -225,6 +235,7 @@ _slang_simplify(slang_operation *oper, oper->literal[1] = oper->children[1].literal[0]; oper->literal[2] = oper->children[2].literal[0]; oper->literal[3] = oper->children[3].literal[0]; + oper->literal_size = 4; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -232,7 +243,7 @@ _slang_simplify(slang_operation *oper, } } - if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) { + if (oper->num_children == 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) { @@ -240,6 +251,7 @@ _slang_simplify(slang_operation *oper, oper->literal[1] = oper->children[1].literal[0]; oper->literal[2] = oper->children[2].literal[0]; oper->literal[3] = oper->literal[2]; + oper->literal_size = 3; slang_operation_destruct(oper); oper->type = slang_oper_literal_float; return; @@ -247,16 +259,20 @@ _slang_simplify(slang_operation *oper, } } - if (n == 2 && isFloat[0] && isFloat[1]) { - /* vec4(flt, flt) constructor */ + if (oper->num_children == 2 && isFloat[0] && isFloat[1]) { + /* vec2(flt, flt) constructor */ if (oper->type == slang_oper_call) { if (strcmp((char *) oper->a_id, "vec2") == 0) { + printf("SIMPLIFY vec2 constructor scope = %p\n", + (void*) oper->locals); 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]; + oper->literal_size = 2; slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */ oper->type = slang_oper_literal_float; + assert(oper->num_children == 0); return; } } diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index 5a3c2eac6b4..eef2cb96db4 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -341,6 +341,21 @@ _slang_typeof_operation_(const slang_operation * op, return GL_FALSE; break; case slang_oper_literal_bool: + if (op->literal_size == 1) + ti->spec.type = slang_spec_bool; + else if (op->literal_size == 2) + ti->spec.type = slang_spec_bvec2; + else if (op->literal_size == 3) + ti->spec.type = slang_spec_bvec3; + else if (op->literal_size == 4) + ti->spec.type = slang_spec_bvec4; + else { + _mesa_problem(NULL, + "Unexpected bool literal_size %d in _slang_typeof_operation()", + op->literal_size); + ti->spec.type = slang_spec_bool; + } + break; case slang_oper_logicalor: case slang_oper_logicalxor: case slang_oper_logicaland: @@ -354,10 +369,36 @@ _slang_typeof_operation_(const slang_operation * op, ti->spec.type = slang_spec_bool; break; case slang_oper_literal_int: - ti->spec.type = slang_spec_int; + if (op->literal_size == 1) + ti->spec.type = slang_spec_int; + else if (op->literal_size == 2) + ti->spec.type = slang_spec_ivec2; + else if (op->literal_size == 3) + ti->spec.type = slang_spec_ivec3; + else if (op->literal_size == 4) + ti->spec.type = slang_spec_ivec4; + else { + _mesa_problem(NULL, + "Unexpected int literal_size %d in _slang_typeof_operation()", + op->literal_size); + ti->spec.type = slang_spec_int; + } break; case slang_oper_literal_float: - ti->spec.type = slang_spec_float; + if (op->literal_size == 1) + ti->spec.type = slang_spec_float; + else if (op->literal_size == 2) + ti->spec.type = slang_spec_vec2; + else if (op->literal_size == 3) + ti->spec.type = slang_spec_vec3; + else if (op->literal_size == 4) + ti->spec.type = slang_spec_vec4; + else { + _mesa_problem(NULL, + "Unexpected float literal_size %d in _slang_typeof_operation()", + op->literal_size); + ti->spec.type = slang_spec_float; + } break; case slang_oper_identifier: { |