From aff8e204d205b5d424d2c39a5d9e004caaa1eab1 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 13 Dec 2006 14:48:36 -0700 Subject: Checkpoint new GLSL compiler back-end to produce fp/vp-style assembly instructions. --- src/mesa/shader/slang/slang_simplify.c | 170 +++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/mesa/shader/slang/slang_simplify.c (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c new file mode 100644 index 0000000000..94e6e1ecc2 --- /dev/null +++ b/src/mesa/shader/slang/slang_simplify.c @@ -0,0 +1,170 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.2 + * + * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file slang_assemble_typeinfo.c + * slang type info + * \author Michal Krol + */ + +#include "imports.h" +#include "macros.h" +#include "slang_compile.h" +#include "slang_simplify.h" + + +/** + * Recursively traverse an AST tree, applying simplifications wherever + * possible. + * At the least, we do constant folding. We need to do that much so that + * compile-time expressions can be evaluated for things like array + * declarations. I.e.: float foo[3 + 5]; + */ +void +slang_simplify(slang_operation *oper, + const slang_assembly_name_space * space, + slang_atom_pool * atoms) +{ + GLboolean isFloat[4]; + GLboolean isBool[4]; + GLuint i, n; + + /* first, simplify children */ + for (i = 0; i < oper->num_children; i++) { + slang_simplify(&oper->children[i], space, atoms); + } + + /* examine children */ + n = MIN2(oper->num_children, 4); + for (i = 0; i < n; i++) { + isFloat[i] = (oper->children[i].type == slang_oper_literal_float || + oper->children[i].type == slang_oper_literal_int); + isBool[i] = (oper->children[i].type == slang_oper_literal_bool); + } + + if (n == 2 && isFloat[0] && isFloat[1]) { + /* probably simple arithmetic */ + switch (oper->type) { + case slang_oper_add: + for (i = 0; i < 4; i++) { + oper->literal[i] + = oper->children[0].literal[i] + oper->children[1].literal[i]; + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + case slang_oper_subtract: + for (i = 0; i < 4; i++) { + oper->literal[i] + = oper->children[0].literal[i] - oper->children[1].literal[i]; + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + case slang_oper_multiply: + for (i = 0; i < 4; i++) { + oper->literal[i] + = oper->children[0].literal[i] * oper->children[1].literal[i]; + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + case slang_oper_divide: + for (i = 0; i < 4; i++) { + oper->literal[i] + = oper->children[0].literal[i] / oper->children[1].literal[i]; + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + default: + ; /* nothing */ + } + } + else if (n == 1 && isFloat[0]) { + switch (oper->type) { + case slang_oper_minus: + for (i = 0; i < 4; i++) { + oper->literal[i] = -oper->children[0].literal[i]; + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + case slang_oper_plus: + COPY_4V(oper->literal, oper->children[0].literal); + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + break; + default: + ; /* nothing */ + } + } + else if (n == 2 && isBool[0] && isBool[1]) { + /* simple boolean expression */ + switch (oper->type) { + case slang_oper_logicaland: + for (i = 0; i < 4; i++) { + const GLint a = oper->children[0].literal[i] ? 1 : 0; + const GLint b = oper->children[1].literal[i] ? 1 : 0; + oper->literal[i] = (GLfloat) (a && b); + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_bool; + break; + case slang_oper_logicalor: + for (i = 0; i < 4; i++) { + const GLint a = oper->children[0].literal[i] ? 1 : 0; + const GLint b = oper->children[1].literal[i] ? 1 : 0; + oper->literal[i] = (GLfloat) (a || b); + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_bool; + break; + case slang_oper_logicalxor: + for (i = 0; i < 4; i++) { + const GLint a = oper->children[0].literal[i] ? 1 : 0; + const GLint b = oper->children[1].literal[i] ? 1 : 0; + oper->literal[i] = (GLfloat) (a ^ b); + } + slang_operation_destruct(oper); + oper->type = slang_oper_literal_bool; + break; + default: + ; /* nothing */ + } + } + else if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) { + if (oper->type == slang_oper_call) { + if (strcmp((char *) oper->a_id, "vec4") == 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] = oper->children[3].literal[0]; + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + } + } + } +} + -- cgit v1.2.3 From 0a097675f174ead793f9c7e3dcd17128279f079b Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 15 Jan 2007 16:34:33 -0700 Subject: added vec3 constructor code --- src/mesa/shader/slang/slang_simplify.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 94e6e1ecc2..dfae746a40 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -155,6 +155,7 @@ slang_simplify(slang_operation *oper, } } else 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) { oper->literal[0] = oper->children[0].literal[0]; @@ -166,5 +167,18 @@ slang_simplify(slang_operation *oper, } } } + else 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; + slang_operation_destruct(oper); + oper->type = slang_oper_literal_float; + } + } + } } -- cgit v1.2.3 From eabb7e66bd6fa9770bcf17833cf9fc6317ae7948 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 17 Jan 2007 16:11:50 -0700 Subject: New _slang_adapt_call() function. This is used to modify function calls (when possible) to make the arguments map to the function parameters. This includes "unrolling" vector types and doing casts. Example: vec2 v2 = vec2(1.2, 3.4) ivec3 iv = ivec3(false, v2); Is converted into: ivec3 iv = ivec3(int(false), int(v2[0]), int(v2[1])) --- src/mesa/shader/slang/slang_simplify.c | 148 +++++++++++++++++++++++++++++++++ src/mesa/shader/slang/slang_simplify.h | 6 ++ 2 files changed, 154 insertions(+) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index dfae746a40..821a716f58 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -31,7 +31,9 @@ #include "imports.h" #include "macros.h" #include "slang_compile.h" +#include "slang_codegen.h" #include "slang_simplify.h" +#include "slang_print.h" /** @@ -182,3 +184,149 @@ slang_simplify(slang_operation *oper, } } + + +/** + * Adapt the arguments for a function call to match the parameters of + * the given function. + * This is for: + * 1. converting/casting argument types to match parameters + * 2. breaking up vector/matrix types into individual components to + * satisfy constructors. + */ +GLboolean +_slang_adapt_call(slang_operation *callOper, const slang_function *fun, + const slang_assembly_name_space * space, + slang_atom_pool * atoms) +{ + const GLboolean haveRetValue = _slang_function_has_return_value(fun); + const int numParams = fun->param_count - haveRetValue; + int i; + int dbg = 0; + + if (dbg) printf("Adapt %d args to %d parameters\n", + callOper->num_children, numParams); + + if (callOper->num_children != numParams) { + /* number of arguments doesn't match number of parameters */ + + if (fun->kind == slang_func_constructor) { + /* For constructor calls, we can try to unroll vector/matrix args + * into individual floats/ints and try to match the function params. + */ + for (i = 0; i < numParams; i++) { + slang_assembly_typeinfo argType; + GLint argSz, j; + + /* Get type of arg[i] */ + if (!slang_assembly_typeinfo_construct(&argType)) + return GL_FALSE; + if (!_slang_typeof_operation_(&callOper->children[i], space, + &argType, atoms)) { + slang_assembly_typeinfo_destruct(&argType); + return GL_FALSE; + } + + /* + paramSz = _slang_sizeof_type_specifier(¶mVar->type.specifier); + assert(paramSz == 1); + */ + argSz = _slang_sizeof_type_specifier(&argType.spec); + if (argSz > 1) { + slang_operation origArg; + /* break up arg[i] into components */ + if (dbg) + printf("Break up arg %d from 1 to %d elements\n", i, argSz); + + slang_operation_construct(&origArg); + slang_operation_copy(&origArg, + &callOper->children[i]); + + /* insert argSz-1 new children/args */ + for (j = 0; j < argSz - 1; j++) { + (void) slang_operation_insert(&callOper->num_children, + &callOper->children, i); + } + + /* replace arg[i+j] with subscript/index oper */ + for (j = 0; j < argSz; j++) { + callOper->children[i + j].type = slang_oper_subscript; + callOper->children[i + j].num_children = 2; + callOper->children[i + j].children = slang_operation_new(2); + slang_operation_copy(&callOper->children[i + j].children[0], + &origArg); + callOper->children[i + j].children[1].type + = slang_oper_literal_int; + callOper->children[i + j].children[1].literal[0] = j; + } + + } + } /* for i */ + } + else { + /* non-constructor function: number of args must match number + * of function params. + */ + return GL_FALSE; /* caller will record an error msg */ + } + } + + if (callOper->num_children < numParams) { + /* still not enough args for all params */ + return GL_FALSE; + } + else if (callOper->num_children > numParams) { + /* now too many arguments */ + /* XXX this isn't always an error, see spec */ + return GL_FALSE; + } + + /* + * Second phase, argument casting. + * Example: + * void foo(int i, bool b) {} + * x = foo(3.15, 9); + * Gets translated into: + * x = foo(int(3.15), bool(9)) + */ + for (i = 0; i < numParams; i++) { + slang_assembly_typeinfo argType; + slang_variable *paramVar = fun->parameters->variables[i]; + + /* Get type of arg[i] */ + if (!slang_assembly_typeinfo_construct(&argType)) + return GL_FALSE; + if (!_slang_typeof_operation_(&callOper->children[i], space, + &argType, atoms)) { + slang_assembly_typeinfo_destruct(&argType); + return GL_FALSE; + } + + /* see if arg type matches parameter type */ + if (!slang_type_specifier_equal(&argType.spec, + ¶mVar->type.specifier)) { + /* need to adapt arg type to match param type */ + const char *constructorName = + slang_type_specifier_type_to_string(paramVar->type.specifier.type); + slang_operation *child = slang_operation_new(1); + + slang_operation_copy(child, &callOper->children[i]); + child->locals->outer_scope = callOper->locals; + + callOper->children[i].type = slang_oper_call; + callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName); + callOper->children[i].num_children = 1; + callOper->children[i].children = child; + } + + slang_assembly_typeinfo_destruct(&argType); + } + + if (dbg) { + printf("===== New call to %s with adapted arguments ===============\n", + (char*) fun->header.a_name); + slang_print_tree(callOper, 5); + } + + return GL_TRUE; +} diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index 69be3092a5..0ca1fa2f0d 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -8,5 +8,11 @@ slang_simplify(slang_operation *oper, slang_atom_pool * atoms); +extern GLboolean +_slang_adapt_call(slang_operation *callOper, const slang_function *fun, + const slang_assembly_name_space * space, + slang_atom_pool * atoms); + + #endif /* SLANG_SIMPLIFY_H */ -- cgit v1.2.3 From 9742547245f3dc4850faa9e83d178d17669d4c09 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 1 Feb 2007 18:11:19 -0700 Subject: Fix logic in _slang_simplify(): vec2() constructor case wasn't getting used. --- src/mesa/shader/slang/slang_codegen.c | 7 +++-- src/mesa/shader/slang/slang_simplify.c | 57 +++++++++++++++++++++++----------- src/mesa/shader/slang/slang_simplify.h | 6 ++-- 3 files changed, 47 insertions(+), 23 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d09883c664..ee1d6cbabc 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 821a716f58..c71313a7bb 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 0ca1fa2f0d..5ff7292f0f 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 -- cgit v1.2.3 From 70570d41996a3754be973ffdc34cd3ae4267878d Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 12:01:29 -0700 Subject: Move guts of slang_lookup_constant() into a new function in slang_simplify.c --- src/mesa/shader/slang/slang_codegen.c | 44 ++++++-------------------- src/mesa/shader/slang/slang_simplify.c | 58 ++++++++++++++++++++++++++++++++++ src/mesa/shader/slang/slang_simplify.h | 5 +++ 3 files changed, 73 insertions(+), 34 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index e384022cea..5ce3e46578 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -29,7 +29,6 @@ */ #include "imports.h" -#include "get.h" #include "macros.h" #include "slang_assemble.h" #include "slang_codegen.h" @@ -61,41 +60,17 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper); * \return position of the constant in the paramList. */ static GLint -slang_lookup_constant(const char *name, GLint index, +slang_lookup_constant(const char *name, struct gl_program_parameter_list *paramList, GLuint *swizzleOut) { - struct constant_info { - const char *Name; - const GLenum Token; - }; - static const struct constant_info info[] = { - { "gl_MaxLights", GL_MAX_LIGHTS }, - { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES }, - { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS }, - { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS }, - { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS }, - { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS }, - { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS }, - { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS }, - { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS }, - { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS }, - { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS }, - { NULL, 0 } - }; - GLuint i; - - for (i = 0; info[i].Name; i++) { - if (strcmp(info[i].Name, name) == 0) { - /* found */ - GLfloat value = -1.0; - GLint pos; - _mesa_GetFloatv(info[i].Token, &value); - ASSERT(value >= 0.0); /* sanity check that glGetFloatv worked */ - /* XXX named constant! */ - pos = _mesa_add_unnamed_constant(paramList, &value, 1, swizzleOut); - return pos; - } + GLint value = _slang_lookup_constant(name); + if (value >= 0) { + /* XXX named constant! */ + GLfloat fvalue = (GLfloat) value; + GLint pos; + pos = _mesa_add_unnamed_constant(paramList, &fvalue, 1, swizzleOut); + return pos; } return -1; } @@ -300,7 +275,8 @@ slang_allocate_storage(slang_assemble_ctx *A, slang_ir_node *n) n->Store->Index = i; } else if (n->Store->File == PROGRAM_CONSTANT) { - GLint i = slang_lookup_constant(varName, 0, prog->Parameters, + /* XXX compile-time constants should be converted to literals */ + GLint i = slang_lookup_constant(varName, prog->Parameters, &n->Store->Swizzle); assert(i >= 0); assert(n->Store->Size == 1); diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index c71313a7bb..19e627489f 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -30,12 +30,57 @@ #include "imports.h" #include "macros.h" +#include "get.h" #include "slang_compile.h" #include "slang_codegen.h" #include "slang_simplify.h" #include "slang_print.h" + + +/** + * Lookup the value of named constant, such as gl_MaxLights. + * \return value of constant, or -1 if unknown + */ +GLint +_slang_lookup_constant(const char *name) +{ + struct constant_info { + const char *Name; + const GLenum Token; + }; + static const struct constant_info info[] = { + { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES }, + { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS }, + { "gl_MaxDrawBuffers", GL_MAX_DRAW_BUFFERS }, + { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS }, + { "gl_MaxLights", GL_MAX_LIGHTS }, + { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS }, + { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS }, + { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS }, + { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS }, + { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS }, + { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS }, + { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS }, + { NULL, 0 } + }; + GLuint i; + + for (i = 0; info[i].Name; i++) { + if (strcmp(info[i].Name, name) == 0) { + /* found */ + GLint value = -1.0; + _mesa_GetIntegerv(info[i].Token, &value); + ASSERT(value >= 0); /* sanity check that glGetFloatv worked */ + return value; + } + } + return -1; +} + + + /** * Recursively traverse an AST tree, applying simplifications wherever * possible. @@ -52,6 +97,19 @@ _slang_simplify(slang_operation *oper, GLboolean isBool[4]; GLuint i, n; + if (oper->type == slang_oper_identifier) { + /* see if it's a named constant */ + GLint value = _slang_lookup_constant((char *) oper->a_id); + if (value >= 0) { + oper->literal[0] = + oper->literal[1] = + oper->literal[2] = + oper->literal[3] = value; + oper->type = slang_oper_literal_int; + return; + } + } + /* first, simplify children */ for (i = 0; i < oper->num_children; i++) { _slang_simplify(&oper->children[i], space, atoms); diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index 5ff7292f0f..b29740eaca 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -2,6 +2,11 @@ #ifndef SLANG_SIMPLIFY_H #define SLANG_SIMPLIFY_H + +extern GLint +_slang_lookup_constant(const char *name); + + extern void _slang_simplify(slang_operation *oper, const slang_assembly_name_space * space, -- cgit v1.2.3 From fe45343df98ecdc06039b68d5a249a41f9e9e11e Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 15:29:48 -0700 Subject: s/slang_assembly_name_space/slang_name_space/ --- src/mesa/shader/slang/slang_codegen.c | 2 +- src/mesa/shader/slang/slang_compile.c | 2 +- src/mesa/shader/slang/slang_simplify.c | 4 ++-- src/mesa/shader/slang/slang_simplify.h | 4 ++-- src/mesa/shader/slang/slang_typeinfo.c | 6 +++--- src/mesa/shader/slang/slang_typeinfo.h | 12 ++++++------ 6 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 222bf113cc..d972118de6 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1267,7 +1267,7 @@ _slang_first_function(struct slang_function_scope_ *scope, const char *name) slang_function * _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, const slang_operation * args, GLuint num_args, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_atom_pool * atoms) { GLuint i; diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 615dfc1bf2..2f4d458b36 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -339,7 +339,7 @@ static GLboolean parse_array_len(slang_parse_ctx * C, slang_output_ctx * O, GLuint * len) { slang_operation array_size; - slang_assembly_name_space space; + slang_name_space space; GLboolean result; if (!slang_operation_construct(&array_size)) diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 19e627489f..bf6afe4532 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -90,7 +90,7 @@ _slang_lookup_constant(const char *name) */ void _slang_simplify(slang_operation *oper, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_atom_pool * atoms) { GLboolean isFloat[4]; @@ -275,7 +275,7 @@ _slang_simplify(slang_operation *oper, */ GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_atom_pool * atoms) { const GLboolean haveRetValue = _slang_function_has_return_value(fun); diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index b29740eaca..d6979a800a 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -9,13 +9,13 @@ _slang_lookup_constant(const char *name); extern void _slang_simplify(slang_operation *oper, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_atom_pool * atoms); extern GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_atom_pool * atoms); diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index fd5cd70a3c..d48113a14a 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -257,7 +257,7 @@ slang_assembly_typeinfo_destruct(slang_assembly_typeinfo * ti) static GLboolean typeof_existing_function(const char *name, const slang_operation * params, GLuint num_params, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_type_specifier * spec, slang_atom_pool * atoms) { @@ -290,7 +290,7 @@ _slang_typeof_operation(const slang_assemble_ctx * A, */ GLboolean _slang_typeof_operation_(const slang_operation * op, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_assembly_typeinfo * ti, slang_atom_pool * atoms) { @@ -616,7 +616,7 @@ _slang_typeof_operation_(const slang_operation * op, GLboolean _slang_typeof_function(slang_atom a_name, const slang_operation * params, GLuint num_params, - const slang_assembly_name_space * space, + const slang_name_space * space, slang_type_specifier * spec, GLboolean * exists, slang_atom_pool * atoms) { diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index b2ca8b8633..267f9abe7b 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -46,18 +46,18 @@ typedef struct slang_swizzle_ GLuint swizzle[4]; } slang_swizzle; -typedef struct slang_assembly_name_space_ +typedef struct slang_name_space_ { struct slang_function_scope_ *funcs; struct slang_struct_scope_ *structs; struct slang_variable_scope_ *vars; -} slang_assembly_name_space; +} slang_name_space; typedef struct slang_assemble_ctx_ { slang_atom_pool *atoms; - slang_assembly_name_space space; + slang_name_space space; slang_swizzle swz; struct gl_program *program; slang_var_table *vartable; @@ -71,7 +71,7 @@ extern struct slang_function_ * _slang_locate_function(const struct slang_function_scope_ *funcs, slang_atom name, const struct slang_operation_ *params, GLuint num_params, - const slang_assembly_name_space *space, + const slang_name_space *space, slang_atom_pool *); @@ -171,7 +171,7 @@ _slang_typeof_operation(const slang_assemble_ctx *, extern GLboolean _slang_typeof_operation_(const struct slang_operation_ *, - const slang_assembly_name_space *, + const slang_name_space *, slang_assembly_typeinfo *, slang_atom_pool *); /** @@ -182,7 +182,7 @@ _slang_typeof_operation_(const struct slang_operation_ *, extern GLboolean _slang_typeof_function(slang_atom a_name, const struct slang_operation_ *params, - GLuint num_params, const slang_assembly_name_space *, + GLuint num_params, const slang_name_space *, slang_type_specifier *spec, GLboolean *exists, slang_atom_pool *); -- cgit v1.2.3 From 1bc71e32ea281077fed6f77bf4c1d63c65eb14f6 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Feb 2007 15:30:50 -0700 Subject: s/slang_assembly_typeinfo/slang_typeinfo/ --- src/mesa/shader/slang/slang_codegen.c | 26 +++++++++--------- src/mesa/shader/slang/slang_compile_operation.h | 2 +- src/mesa/shader/slang/slang_simplify.c | 14 +++++----- src/mesa/shader/slang/slang_typeinfo.c | 36 ++++++++++++------------- src/mesa/shader/slang/slang_typeinfo.h | 12 ++++----- 5 files changed, 45 insertions(+), 45 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d972118de6..295292e076 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1284,20 +1284,20 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, /* compare parameter / argument types */ for (j = 0; j < num_args; j++) { - slang_assembly_typeinfo ti; + slang_typeinfo ti; - if (!slang_assembly_typeinfo_construct(&ti)) + if (!slang_typeinfo_construct(&ti)) return NULL; if (!_slang_typeof_operation_(&args[j], space, &ti, atoms)) { - slang_assembly_typeinfo_destruct(&ti); + slang_typeinfo_destruct(&ti); return NULL; } if (!slang_type_specifier_equal(&ti.spec, &f->parameters->variables[j/* + haveRetValue*/]->type.specifier)) { - slang_assembly_typeinfo_destruct(&ti); + slang_typeinfo_destruct(&ti); break; } - slang_assembly_typeinfo_destruct(&ti); + slang_typeinfo_destruct(&ti); /* "out" and "inout" formal parameter requires the actual parameter to be l-value */ if (!ti.can_be_referenced && @@ -1667,14 +1667,14 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *altLab, *endLab; slang_ir_node *tree, *tmpDecl, *tmpVar, *cond, *cjump, *jump; slang_ir_node *bodx, *body, *assignx, *assigny; - slang_assembly_typeinfo type; + slang_typeinfo type; int size; assert(oper->type == slang_oper_select); assert(oper->num_children == 3); /* size of x or y's type */ - slang_assembly_typeinfo_construct(&type); + slang_typeinfo_construct(&type); _slang_typeof_operation(A, &oper->children[1], &type); size = _slang_sizeof_type_specifier(&type.spec); assert(size > 0); @@ -2110,9 +2110,9 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper) static slang_ir_node * _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) { - slang_assembly_typeinfo ti; + slang_typeinfo ti; - slang_assembly_typeinfo_construct(&ti); + slang_typeinfo_construct(&ti); _slang_typeof_operation(A, &oper->children[0], &ti); if (_slang_type_is_vector(ti.spec.type)) { @@ -2167,10 +2167,10 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) static slang_ir_node * _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) { - slang_assembly_typeinfo array_ti; + slang_typeinfo array_ti; /* get array's type info */ - slang_assembly_typeinfo_construct(&array_ti); + slang_typeinfo_construct(&array_ti); _slang_typeof_operation(A, &oper->children[0], &array_ti); if (_slang_type_is_vector(array_ti.spec.type)) { @@ -2201,12 +2201,12 @@ _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) } else { /* conventional array */ - slang_assembly_typeinfo elem_ti; + slang_typeinfo elem_ti; slang_ir_node *elem, *array, *index; GLint elemSize; /* size of array element */ - slang_assembly_typeinfo_construct(&elem_ti); + slang_typeinfo_construct(&elem_ti); _slang_typeof_operation(A, oper, &elem_ti); elemSize = _slang_sizeof_type_specifier(&elem_ti.spec); assert(elemSize >= 1); diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h index ad52b6690d..0ce9bbad81 100644 --- a/src/mesa/shader/slang/slang_compile_operation.h +++ b/src/mesa/shader/slang/slang_compile_operation.h @@ -122,7 +122,7 @@ typedef struct slang_operation_ struct slang_function_ *fun; /**< If type == slang_oper_call */ struct slang_variable_ *var; /**< If type == slang_oper_identier */ slang_fully_specified_type *datatype; /**< Type of this operation */ - slang_assembly_typeinfo ti; + slang_typeinfo ti; } slang_operation; diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index bf6afe4532..ef8b2fedd8 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -294,15 +294,15 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, * into individual floats/ints and try to match the function params. */ for (i = 0; i < numParams; i++) { - slang_assembly_typeinfo argType; + slang_typeinfo argType; GLint argSz, j; /* Get type of arg[i] */ - if (!slang_assembly_typeinfo_construct(&argType)) + if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, &argType, atoms)) { - slang_assembly_typeinfo_destruct(&argType); + slang_typeinfo_destruct(&argType); return GL_FALSE; } @@ -369,15 +369,15 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, * x = foo(int(3.15), bool(9)) */ for (i = 0; i < numParams; i++) { - slang_assembly_typeinfo argType; + slang_typeinfo argType; slang_variable *paramVar = fun->parameters->variables[i]; /* Get type of arg[i] */ - if (!slang_assembly_typeinfo_construct(&argType)) + if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, &argType, atoms)) { - slang_assembly_typeinfo_destruct(&argType); + slang_typeinfo_destruct(&argType); return GL_FALSE; } @@ -398,7 +398,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, callOper->children[i].children = child; } - slang_assembly_typeinfo_destruct(&argType); + slang_typeinfo_destruct(&argType); } if (dbg) { diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index d48113a14a..cfed54276d 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -230,7 +230,7 @@ slang_type_specifier_equal(const slang_type_specifier * x, GLboolean -slang_assembly_typeinfo_construct(slang_assembly_typeinfo * ti) +slang_typeinfo_construct(slang_typeinfo * ti) { slang_type_specifier_ctr(&ti->spec); ti->array_len = 0; @@ -238,7 +238,7 @@ slang_assembly_typeinfo_construct(slang_assembly_typeinfo * ti) } GLvoid -slang_assembly_typeinfo_destruct(slang_assembly_typeinfo * ti) +slang_typeinfo_destruct(slang_typeinfo * ti) { slang_type_specifier_dtr(&ti->spec); } @@ -274,7 +274,7 @@ typeof_existing_function(const char *name, const slang_operation * params, GLboolean _slang_typeof_operation(const slang_assemble_ctx * A, const slang_operation * op, - slang_assembly_typeinfo * ti) + slang_typeinfo * ti) { return _slang_typeof_operation_(op, &A->space, ti, A->atoms); } @@ -291,7 +291,7 @@ _slang_typeof_operation(const slang_assemble_ctx * A, GLboolean _slang_typeof_operation_(const slang_operation * op, const slang_name_space * space, - slang_assembly_typeinfo * ti, + slang_typeinfo * ti, slang_atom_pool * atoms) { ti->can_be_referenced = GL_FALSE; @@ -415,30 +415,30 @@ _slang_typeof_operation_(const slang_operation * op, /*case slang_oper_complement: */ case slang_oper_subscript: { - slang_assembly_typeinfo _ti; + slang_typeinfo _ti; - if (!slang_assembly_typeinfo_construct(&_ti)) + if (!slang_typeinfo_construct(&_ti)) RETURN_NIL(); if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_NIL(); } ti->can_be_referenced = _ti.can_be_referenced; if (_ti.spec.type == slang_spec_array) { if (!slang_type_specifier_copy(&ti->spec, _ti.spec._array)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_NIL(); } } else { if (!_slang_type_is_vector(_ti.spec.type) && !_slang_type_is_matrix(_ti.spec.type)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_ERROR("cannot index a non-array type", 0); } ti->spec.type = _slang_type_base(_ti.spec.type); } - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); } break; case slang_oper_call: @@ -480,12 +480,12 @@ _slang_typeof_operation_(const slang_operation * op, break; case slang_oper_field: { - slang_assembly_typeinfo _ti; + slang_typeinfo _ti; - if (!slang_assembly_typeinfo_construct(&_ti)) + if (!slang_typeinfo_construct(&_ti)) RETURN_NIL(); if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_NIL(); } if (_ti.spec.type == slang_spec_struct) { @@ -494,11 +494,11 @@ _slang_typeof_operation_(const slang_operation * op, field = _slang_locate_variable(_ti.spec._struct->fields, op->a_id, GL_FALSE); if (field == NULL) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_NIL(); } if (!slang_type_specifier_copy(&ti->spec, &field->type.specifier)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_NIL(); } ti->can_be_referenced = _ti.can_be_referenced; @@ -511,14 +511,14 @@ _slang_typeof_operation_(const slang_operation * op, /* determine the swizzle of the field expression */ #if 000 if (!_slang_type_is_vector(_ti.spec.type)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_ERROR("Can't swizzle scalar expression", 0); } #endif rows = _slang_type_dim(_ti.spec.type); swizzle = slang_atom_pool_id(atoms, op->a_id); if (!_slang_is_swizzle(swizzle, rows, &ti->swz)) { - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); RETURN_ERROR("Bad swizzle", 0); } ti->is_swizzled = GL_TRUE; @@ -585,7 +585,7 @@ _slang_typeof_operation_(const slang_operation * op, break; } } - slang_assembly_typeinfo_destruct(&_ti); + slang_typeinfo_destruct(&_ti); } break; case slang_oper_postincrement: diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index 267f9abe7b..71ed9b7a53 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -143,20 +143,20 @@ slang_type_specifier_equal(const slang_type_specifier *, const slang_type_specifier *); -typedef struct slang_assembly_typeinfo_ +typedef struct slang_typeinfo_ { GLboolean can_be_referenced; GLboolean is_swizzled; slang_swizzle swz; slang_type_specifier spec; GLuint array_len; -} slang_assembly_typeinfo; +} slang_typeinfo; extern GLboolean -slang_assembly_typeinfo_construct(slang_assembly_typeinfo *); +slang_typeinfo_construct(slang_typeinfo *); extern GLvoid -slang_assembly_typeinfo_destruct(slang_assembly_typeinfo *); +slang_typeinfo_destruct(slang_typeinfo *); /** @@ -167,12 +167,12 @@ slang_assembly_typeinfo_destruct(slang_assembly_typeinfo *); extern GLboolean _slang_typeof_operation(const slang_assemble_ctx *, const struct slang_operation_ *, - slang_assembly_typeinfo *); + slang_typeinfo *); extern GLboolean _slang_typeof_operation_(const struct slang_operation_ *, const slang_name_space *, - slang_assembly_typeinfo *, slang_atom_pool *); + slang_typeinfo *, slang_atom_pool *); /** * Retrieves type of a function prototype, if one exists. -- cgit v1.2.3 From 93b975a1d9fcc4a10987676f7368809522f27d71 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 3 Feb 2007 17:24:24 -0700 Subject: 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))" --- src/mesa/shader/slang/slang_codegen.c | 14 +++++++- src/mesa/shader/slang/slang_compile.c | 3 ++ src/mesa/shader/slang/slang_compile_operation.c | 2 ++ src/mesa/shader/slang/slang_compile_operation.h | 1 + src/mesa/shader/slang/slang_simplify.c | 30 +++++++++++++---- src/mesa/shader/slang/slang_typeinfo.c | 45 +++++++++++++++++++++++-- 6 files changed, 85 insertions(+), 10 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 4cb161a5b6..6b7df0597b 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 619fe50ce5..199f96e441 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 c16ec7f807..51a64ca30b 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 121b5832ef..3f5b1bb8f3 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 ef8b2fedd8..0e433281e8 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 5a3c2eac6b..eef2cb96db 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: { -- cgit v1.2.3 From 1c1a0a23d32f889971de61c2c25fa1eebb9889a3 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 16 Feb 2007 09:31:35 -0700 Subject: change all enum tokens to uppercase --- src/mesa/shader/slang/slang_codegen.c | 318 ++++++++++++------------ src/mesa/shader/slang/slang_compile.c | 224 ++++++++--------- src/mesa/shader/slang/slang_compile.h | 13 +- src/mesa/shader/slang/slang_compile_function.c | 6 +- src/mesa/shader/slang/slang_compile_function.h | 6 +- src/mesa/shader/slang/slang_compile_operation.c | 2 +- src/mesa/shader/slang/slang_compile_operation.h | 130 +++++----- src/mesa/shader/slang/slang_compile_struct.c | 2 +- src/mesa/shader/slang/slang_compile_variable.c | 92 +++---- src/mesa/shader/slang/slang_compile_variable.h | 20 +- src/mesa/shader/slang/slang_print.c | 278 ++++++++++----------- src/mesa/shader/slang/slang_simplify.c | 66 ++--- src/mesa/shader/slang/slang_storage.c | 96 +++---- src/mesa/shader/slang/slang_storage.h | 17 +- src/mesa/shader/slang/slang_typeinfo.c | 318 ++++++++++++------------ src/mesa/shader/slang/slang_typeinfo.h | 48 ++-- 16 files changed, 819 insertions(+), 817 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index c4535feac1..a36a2d7bc9 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -142,12 +142,12 @@ static GLboolean is_sampler_type(const slang_fully_specified_type *t) { switch (t->specifier.type) { - case slang_spec_sampler1D: - case slang_spec_sampler2D: - case slang_spec_sampler3D: - case slang_spec_samplerCube: - case slang_spec_sampler1DShadow: - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER1D: + case SLANG_SPEC_SAMPLER2D: + case SLANG_SPEC_SAMPLER3D: + case SLANG_SPEC_SAMPLERCUBE: + case SLANG_SPEC_SAMPLER1DSHADOW: + case SLANG_SPEC_SAMPLER2DSHADOW: return GL_TRUE; default: return GL_FALSE; @@ -167,49 +167,49 @@ GLuint _slang_sizeof_type_specifier(const slang_type_specifier *spec) { switch (spec->type) { - case slang_spec_void: + case SLANG_SPEC_VOID: abort(); return 0; - case slang_spec_bool: + case SLANG_SPEC_BOOL: return 1; - case slang_spec_bvec2: + case SLANG_SPEC_BVEC2: return 2; - case slang_spec_bvec3: + case SLANG_SPEC_BVEC3: return 3; - case slang_spec_bvec4: + case SLANG_SPEC_BVEC4: return 4; - case slang_spec_int: + case SLANG_SPEC_INT: return 1; - case slang_spec_ivec2: + case SLANG_SPEC_IVEC2: return 2; - case slang_spec_ivec3: + case SLANG_SPEC_IVEC3: return 3; - case slang_spec_ivec4: + case SLANG_SPEC_IVEC4: return 4; - case slang_spec_float: + case SLANG_SPEC_FLOAT: return 1; - case slang_spec_vec2: + case SLANG_SPEC_VEC2: return 2; - case slang_spec_vec3: + case SLANG_SPEC_VEC3: return 3; - case slang_spec_vec4: + case SLANG_SPEC_VEC4: return 4; - case slang_spec_mat2: + case SLANG_SPEC_MAT2: return 2 * 2; - case slang_spec_mat3: + case SLANG_SPEC_MAT3: return 3 * 3; - case slang_spec_mat4: + case SLANG_SPEC_MAT4: return 4 * 4; - case slang_spec_sampler1D: - case slang_spec_sampler2D: - case slang_spec_sampler3D: - case slang_spec_samplerCube: - case slang_spec_sampler1DShadow: - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER1D: + case SLANG_SPEC_SAMPLER2D: + case SLANG_SPEC_SAMPLER3D: + case SLANG_SPEC_SAMPLERCUBE: + case SLANG_SPEC_SAMPLER1DSHADOW: + case SLANG_SPEC_SAMPLER2DSHADOW: return 1; /* special case */ - case slang_spec_struct: + case SLANG_SPEC_STRUCT: return _slang_sizeof_struct(spec->_struct); - case slang_spec_array: + case SLANG_SPEC_ARRAY: return 1; /* XXX */ default: abort(); @@ -295,17 +295,17 @@ static GLint sampler_to_texture_index(const slang_type_specifier_type type) { switch (type) { - case slang_spec_sampler1D: + case SLANG_SPEC_SAMPLER1D: return TEXTURE_1D_INDEX; - case slang_spec_sampler2D: + case SLANG_SPEC_SAMPLER2D: return TEXTURE_2D_INDEX; - case slang_spec_sampler3D: + case SLANG_SPEC_SAMPLER3D: return TEXTURE_3D_INDEX; - case slang_spec_samplerCube: + case SLANG_SPEC_SAMPLERCUBE: return TEXTURE_CUBE_INDEX; - case slang_spec_sampler1DShadow: + case SLANG_SPEC_SAMPLER1DSHADOW: return TEXTURE_1D_INDEX; /* XXX fix */ - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER2DSHADOW: return TEXTURE_2D_INDEX; /* XXX fix */ default: return -1; @@ -708,9 +708,9 @@ new_var(slang_assemble_ctx *A, slang_operation *oper, slang_atom name) static GLboolean slang_is_asm_function(const slang_function *fun) { - if (fun->body->type == slang_oper_block_no_new_scope && + if (fun->body->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE && fun->body->num_children == 1 && - fun->body->children[0].type == slang_oper_asm) { + fun->body->children[0].type == SLANG_OPER_ASM) { return GL_TRUE; } return GL_FALSE; @@ -729,7 +729,7 @@ slang_inline_asm_function(slang_assemble_ctx *A, GLuint i; slang_operation *inlined = slang_operation_new(1); - /*assert(oper->type == slang_oper_call); or vec4_add, etc */ + /*assert(oper->type == SLANG_OPER_CALL); or vec4_add, etc */ /* printf("Inline asm %s\n", (char*) fun->header.a_name); */ @@ -755,7 +755,7 @@ slang_inline_asm_function(slang_assemble_ctx *A, static void slang_resolve_variable(slang_operation *oper) { - if (oper->type != slang_oper_identifier) + if (oper->type != SLANG_OPER_IDENTIFIER) return; if (!oper->var) { oper->var = _slang_locate_variable(oper->locals, @@ -768,7 +768,7 @@ slang_resolve_variable(slang_operation *oper) /** - * Replace particular variables (slang_oper_identifier) with new expressions. + * Replace particular variables (SLANG_OPER_IDENTIFIER) with new expressions. */ static void slang_substitute(slang_assemble_ctx *A, slang_operation *oper, @@ -776,7 +776,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, slang_operation **substNew, GLboolean isLHS) { switch (oper->type) { - case slang_oper_variable_decl: + case SLANG_OPER_VARIABLE_DECL: { slang_variable *v = _slang_locate_variable(oper->locals, oper->a_id, GL_TRUE); @@ -793,7 +793,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, } } break; - case slang_oper_identifier: + case SLANG_OPER_IDENTIFIER: assert(oper->num_children == 0); if (1/**!isLHS XXX FIX */) { slang_atom id = oper->a_id; @@ -811,9 +811,9 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, /* look for a substitution */ for (i = 0; i < substCount; i++) { if (v == substOld[i]) { - /* OK, replace this slang_oper_identifier with a new expr */ + /* OK, replace this SLANG_OPER_IDENTIFIER with a new expr */ #if 0 /* DEBUG only */ - if (substNew[i]->type == slang_oper_identifier) { + if (substNew[i]->type == SLANG_OPER_IDENTIFIER) { assert(substNew[i]->var); assert(substNew[i]->var->a_name); printf("Substitute %s with %s in id node %p\n", @@ -833,7 +833,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, } break; #if 1 /* XXX rely on default case below */ - case slang_oper_return: + case SLANG_OPER_RETURN: /* do return replacement here too */ assert(oper->num_children == 0 || oper->num_children == 1); if (oper->num_children == 1) { @@ -846,23 +846,23 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, */ slang_operation *blockOper, *assignOper, *returnOper; blockOper = slang_operation_new(1); - blockOper->type = slang_oper_block_no_new_scope; + blockOper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; blockOper->num_children = 2; blockOper->children = slang_operation_new(2); assignOper = blockOper->children + 0; returnOper = blockOper->children + 1; - assignOper->type = slang_oper_assign; + assignOper->type = SLANG_OPER_ASSIGN; assignOper->num_children = 2; assignOper->children = slang_operation_new(2); - assignOper->children[0].type = slang_oper_identifier; + assignOper->children[0].type = SLANG_OPER_IDENTIFIER; assignOper->children[0].a_id = slang_atom_pool_atom(A->atoms, "__retVal"); assignOper->children[0].locals->outer_scope = oper->locals; assignOper->locals = oper->locals; slang_operation_copy(&assignOper->children[1], &oper->children[0]); - returnOper->type = slang_oper_return; + returnOper->type = SLANG_OPER_RETURN; assert(returnOper->num_children == 0); /* do substitutions on the "__retVal = expr" sub-tree */ @@ -875,8 +875,8 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, } break; #endif - case slang_oper_assign: - case slang_oper_subscript: + case SLANG_OPER_ASSIGN: + case SLANG_OPER_SUBSCRIPT: /* special case: * child[0] can't have substitutions but child[1] can. */ @@ -885,7 +885,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, slang_substitute(A, &oper->children[1], substCount, substOld, substNew, GL_FALSE); break; - case slang_oper_field: + case SLANG_OPER_FIELD: /* XXX NEW - test */ slang_substitute(A, &oper->children[0], substCount, substOld, substNew, GL_TRUE); @@ -925,7 +925,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_operation **substNew; GLuint substCount, numCopyIn, i; - /*assert(oper->type == slang_oper_call); (or (matrix) multiply, etc) */ + /*assert(oper->type == SLANG_OPER_CALL); (or (matrix) multiply, etc) */ assert(fun->param_count == totalArgs); /* allocate temporary arrays */ @@ -953,7 +953,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_variable *resultVar; commaSeq = slang_operation_new(1); - commaSeq->type = slang_oper_sequence; + commaSeq->type = SLANG_OPER_SEQUENCE; assert(commaSeq->locals); commaSeq->locals->outer_scope = oper->locals->outer_scope; commaSeq->num_children = 3; @@ -971,7 +971,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* child[0] = __resultTmp declaration */ declOper = &commaSeq->children[0]; - declOper->type = slang_oper_variable_decl; + declOper->type = SLANG_OPER_VARIABLE_DECL; declOper->a_id = resultVar->a_name; declOper->locals->outer_scope = commaSeq->locals; /*** ??? **/ @@ -982,7 +982,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* child[2] = __resultTmp reference */ returnOper = &commaSeq->children[2]; - returnOper->type = slang_oper_identifier; + returnOper->type = SLANG_OPER_IDENTIFIER; returnOper->a_id = resultVar->a_name; returnOper->locals->outer_scope = commaSeq->locals; declOper->locals->outer_scope = commaSeq->locals; @@ -1013,8 +1013,8 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_type_qual_string(p->type.qualifier), (char *) p->a_name); */ - if (p->type.qualifier == slang_qual_inout || - p->type.qualifier == slang_qual_out) { + if (p->type.qualifier == SLANG_QUAL_INOUT || + p->type.qualifier == SLANG_QUAL_OUT) { /* an output param */ slang_operation *arg; if (i < numArgs) @@ -1023,7 +1023,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, arg = returnOper; paramMode[i] = SUBST; - if (arg->type == slang_oper_identifier) + if (arg->type == SLANG_OPER_IDENTIFIER) slang_resolve_variable(arg); /* replace parameter 'p' with argument 'arg' */ @@ -1031,10 +1031,10 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, substNew[substCount] = arg; /* will get copied */ substCount++; } - else if (p->type.qualifier == slang_qual_const) { + else if (p->type.qualifier == SLANG_QUAL_CONST) { /* a constant input param */ - if (args[i].type == slang_oper_identifier || - args[i].type == slang_oper_literal_float) { + if (args[i].type == SLANG_OPER_IDENTIFIER || + args[i].type == SLANG_OPER_LITERAL_FLOAT) { /* replace all occurances of this parameter variable with the * actual argument variable or a literal. */ @@ -1058,8 +1058,8 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_operation_copy(inlined, fun->body); /*** XXX review this */ - assert(inlined->type = slang_oper_block_no_new_scope); - inlined->type = slang_oper_block_new_scope; + assert(inlined->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE); + inlined->type = SLANG_OPER_BLOCK_NEW_SCOPE; #if 0 printf("======================= orig body code ======================\n"); @@ -1092,7 +1092,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* printf("COPY_IN %s from expr\n", (char*)p->a_name); */ - decl->type = slang_oper_variable_decl; + decl->type = SLANG_OPER_VARIABLE_DECL; assert(decl->locals); decl->locals = fun->parameters; decl->a_id = p->a_name; @@ -1114,7 +1114,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_operation *lab = slang_operation_insert(&inlined->num_children, &inlined->children, inlined->num_children); - lab->type = slang_oper_label; + lab->type = SLANG_OPER_LABEL; lab->a_id = slang_atom_pool_atom(A->atoms, (char *) A->CurFunction->end_label); } @@ -1127,13 +1127,13 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, slang_operation *ass = slang_operation_insert(&inlined->num_children, &inlined->children, inlined->num_children); - ass->type = slang_oper_assign; + ass->type = SLANG_OPER_ASSIGN; ass->num_children = 2; ass->locals = _slang_variable_scope_new(inlined->locals); assert(ass->locals); ass->children = slang_operation_new(2); ass->children[0] = args[i]; /*XXX copy */ - ass->children[1].type = slang_oper_identifier; + ass->children[1].type = SLANG_OPER_IDENTIFIER; ass->children[1].a_id = p->a_name; ass->children[1].locals = _slang_variable_scope_new(ass->locals); } @@ -1261,7 +1261,7 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, slang_ir_node *kids[3], *n; GLuint j, firstOperand; - assert(oper->type == slang_oper_asm); + assert(oper->type == SLANG_OPER_ASM); info = slang_find_asm_info((char *) oper->a_id); if (!info) { @@ -1301,7 +1301,7 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, slang_ir_node *n0; dest_oper = &oper->children[0]; - while /*if*/ (dest_oper->type == slang_oper_field) { + while /*if*/ (dest_oper->type == SLANG_OPER_FIELD) { /* writemask */ writemask &= /*=*/make_writemask((char*) dest_oper->a_id); dest_oper = &dest_oper->children[0]; @@ -1326,8 +1326,8 @@ static GLboolean _slang_is_noop(const slang_operation *oper) { if (!oper || - oper->type == slang_oper_void || - (oper->num_children == 1 && oper->children[0].type == slang_oper_void)) + oper->type == SLANG_OPER_VOID || + (oper->num_children == 1 && oper->children[0].type == SLANG_OPER_VOID)) return GL_TRUE; else return GL_FALSE; @@ -1414,16 +1414,16 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, static GLboolean _slang_is_constant_cond(const slang_operation *oper, GLboolean *value) { - if (oper->type == slang_oper_literal_float || - oper->type == slang_oper_literal_int || - oper->type == slang_oper_literal_bool) { + if (oper->type == SLANG_OPER_LITERAL_FLOAT || + oper->type == SLANG_OPER_LITERAL_INT || + oper->type == SLANG_OPER_LITERAL_BOOL) { if (oper->literal[0]) *value = GL_TRUE; else *value = GL_FALSE; return GL_TRUE; } - else if (oper->type == slang_oper_expression && + else if (oper->type == SLANG_OPER_EXPRESSION && oper->num_children == 1) { return _slang_is_constant_cond(&oper->children[0], value); } @@ -1620,8 +1620,8 @@ is_operation_type(const const slang_operation *oper, slang_operation_type type) { if (oper->type == type) return GL_TRUE; - else if ((oper->type == slang_oper_block_new_scope || - oper->type == slang_oper_block_no_new_scope) && + else if ((oper->type == SLANG_OPER_BLOCK_NEW_SCOPE || + oper->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE) && oper->num_children == 1) return is_operation_type(&oper->children[0], type); else @@ -1650,7 +1650,7 @@ _slang_gen_hl_if(slang_assemble_ctx * A, const slang_operation *oper) cond = _slang_gen_operation(A, &oper->children[0]); cond = new_cond(cond); - if (is_operation_type(&oper->children[1], slang_oper_break)) { + if (is_operation_type(&oper->children[1], SLANG_OPER_BREAK)) { /* Special case: generate a conditional break */ ifBody = new_break_if(A->CurLoop, cond, GL_TRUE); if (haveElseClause) { @@ -1659,7 +1659,7 @@ _slang_gen_hl_if(slang_assemble_ctx * A, const slang_operation *oper) } return ifBody; } - else if (is_operation_type(&oper->children[1], slang_oper_continue)) { + else if (is_operation_type(&oper->children[1], SLANG_OPER_CONTINUE)) { /* Special case: generate a conditional break */ ifBody = new_cont_if(A->CurLoop, cond, GL_TRUE); if (haveElseClause) { @@ -1744,7 +1744,7 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) slang_typeinfo type; int size; - assert(oper->type == slang_oper_select); + assert(oper->type == SLANG_OPER_SELECT); assert(oper->num_children == 3); /* size of x or y's type */ @@ -1811,13 +1811,13 @@ _slang_gen_logical_and(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *n; select = slang_operation_new(1); - select->type = slang_oper_select; + select->type = SLANG_OPER_SELECT; select->num_children = 3; select->children = slang_operation_new(3); slang_operation_copy(&select->children[0], &oper->children[0]); slang_operation_copy(&select->children[1], &oper->children[1]); - select->children[2].type = slang_oper_literal_bool; + select->children[2].type = SLANG_OPER_LITERAL_BOOL; ASSIGN_4V(select->children[2].literal, 0, 0, 0, 0); select->children[2].literal_size = 2; @@ -1842,12 +1842,12 @@ _slang_gen_logical_or(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *n; select = slang_operation_new(1); - select->type = slang_oper_select; + select->type = SLANG_OPER_SELECT; select->num_children = 3; select->children = slang_operation_new(3); slang_operation_copy(&select->children[0], &oper->children[0]); - select->children[1].type = slang_oper_literal_bool; + 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; @@ -1871,7 +1871,7 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) { if (oper->num_children == 0 || (oper->num_children == 1 && - oper->children[0].type == slang_oper_void)) { + oper->children[0].type == SLANG_OPER_VOID)) { /* Convert from: * return; * To: @@ -1880,7 +1880,7 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; slang_operation gotoOp; slang_operation_construct(&gotoOp); - gotoOp.type = slang_oper_goto; + gotoOp.type = SLANG_OPER_GOTO; /* XXX don't call function? */ gotoOp.a_id = slang_atom_pool_atom(A->atoms, (char *) A->CurFunction->end_label); @@ -1914,7 +1914,7 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) #endif block = slang_operation_new(1); - block->type = slang_oper_block_no_new_scope; + block->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; block->num_children = 2; block->children = slang_operation_new(2); assert(block->locals); @@ -1922,12 +1922,12 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) /* child[0]: __retVal = expr; */ assign = &block->children[0]; - assign->type = slang_oper_assign; + assign->type = SLANG_OPER_ASSIGN; assign->locals->outer_scope = block->locals; assign->num_children = 2; assign->children = slang_operation_new(2); /* lhs (__retVal) */ - assign->children[0].type = slang_oper_identifier; + assign->children[0].type = SLANG_OPER_IDENTIFIER; assign->children[0].a_id = a_retVal; assign->children[0].locals->outer_scope = assign->locals; /* rhs (expr) */ @@ -1936,7 +1936,7 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) /* child[1]: goto __endOfFunction */ jump = &block->children[1]; - jump->type = slang_oper_goto; + jump->type = SLANG_OPER_GOTO; assert(A->CurFunction->end_label); /* XXX don't call function? */ jump->a_id = slang_atom_pool_atom(A->atoms, @@ -2150,8 +2150,8 @@ _slang_gen_swizzle(slang_ir_node *child, GLuint swizzle) static slang_ir_node * _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper) { - if (oper->children[0].type == slang_oper_identifier && - oper->children[1].type == slang_oper_call) { + if (oper->children[0].type == SLANG_OPER_IDENTIFIER && + oper->children[1].type == SLANG_OPER_CALL) { /* Special case of: x = f(a, b) * Replace with f(a, b, x) (where x == hidden __retVal out param) * @@ -2220,7 +2220,7 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) n = _slang_gen_swizzle(n, swizzle); return n; } - else if (ti.spec.type == slang_spec_float) { + else if (ti.spec.type == SLANG_SPEC_FLOAT) { const GLuint rows = 1; slang_swizzle swz; slang_ir_node *n; @@ -2267,7 +2267,7 @@ _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; index = (GLint) oper->children[1].literal[0]; - if (oper->children[1].type != slang_oper_literal_int || + if (oper->children[1].type != SLANG_OPER_LITERAL_INT || index >= max) { RETURN_ERROR("Invalid array index for vector type", 0); } @@ -2321,15 +2321,15 @@ static slang_ir_node * _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) { switch (oper->type) { - case slang_oper_block_new_scope: + case SLANG_OPER_BLOCK_NEW_SCOPE: { slang_ir_node *n; _slang_push_var_table(A->vartable); - oper->type = slang_oper_block_no_new_scope; /* temp change */ + oper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; /* temp change */ n = _slang_gen_operation(A, oper); - oper->type = slang_oper_block_new_scope; /* restore */ + oper->type = SLANG_OPER_BLOCK_NEW_SCOPE; /* restore */ _slang_pop_var_table(A->vartable); @@ -2339,7 +2339,7 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) } break; - case slang_oper_block_no_new_scope: + case SLANG_OPER_BLOCK_NO_NEW_SCOPE: /* list of operations */ if (oper->num_children > 0) { @@ -2378,104 +2378,104 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return tree; } break; - case slang_oper_expression: + case SLANG_OPER_EXPRESSION: return _slang_gen_operation(A, &oper->children[0]); - case slang_oper_for: + case SLANG_OPER_FOR: return _slang_gen_for(A, oper); - case slang_oper_do: + case SLANG_OPER_DO: return _slang_gen_do(A, oper); - case slang_oper_while: + case SLANG_OPER_WHILE: return _slang_gen_while(A, oper); - case slang_oper_break: + case SLANG_OPER_BREAK: if (!A->CurLoop) { RETURN_ERROR("'break' not in loop", 0); } return new_break(A->CurLoop); - case slang_oper_continue: + case SLANG_OPER_CONTINUE: if (!A->CurLoop) { RETURN_ERROR("'continue' not in loop", 0); } return new_cont(A->CurLoop); - case slang_oper_discard: + case SLANG_OPER_DISCARD: return new_node0(IR_KILL); - case slang_oper_equal: + case SLANG_OPER_EQUAL: return new_node2(IR_SEQUAL, _slang_gen_operation(A, &oper->children[0]), _slang_gen_operation(A, &oper->children[1])); - case slang_oper_notequal: + case SLANG_OPER_NOTEQUAL: return new_node2(IR_SNEQUAL, _slang_gen_operation(A, &oper->children[0]), _slang_gen_operation(A, &oper->children[1])); - case slang_oper_greater: + case SLANG_OPER_GREATER: return new_node2(IR_SGT, _slang_gen_operation(A, &oper->children[0]), _slang_gen_operation(A, &oper->children[1])); - case slang_oper_less: + case SLANG_OPER_LESS: /* child[0] < child[1] ----> child[1] > child[0] */ return new_node2(IR_SGT, _slang_gen_operation(A, &oper->children[1]), _slang_gen_operation(A, &oper->children[0])); - case slang_oper_greaterequal: + case SLANG_OPER_GREATERequal: return new_node2(IR_SGE, _slang_gen_operation(A, &oper->children[0]), _slang_gen_operation(A, &oper->children[1])); - case slang_oper_lessequal: + case SLANG_OPER_LESSequal: /* child[0] <= child[1] ----> child[1] >= child[0] */ return new_node2(IR_SGE, _slang_gen_operation(A, &oper->children[1]), _slang_gen_operation(A, &oper->children[0])); - case slang_oper_add: + case SLANG_OPER_ADD: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "+", oper, NULL); return n; } - case slang_oper_subtract: + case SLANG_OPER_SUBTRACT: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "-", oper, NULL); return n; } - case slang_oper_multiply: + case SLANG_OPER_MULTIPLY: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "*", oper, NULL); return n; } - case slang_oper_divide: + case SLANG_OPER_DIVIDE: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "/", oper, NULL); return n; } - case slang_oper_minus: + case SLANG_OPER_MINUS: { slang_ir_node *n; assert(oper->num_children == 1); n = _slang_gen_function_call_name(A, "-", oper, NULL); return n; } - case slang_oper_plus: + case SLANG_OPER_PLUS: /* +expr --> do nothing */ return _slang_gen_operation(A, &oper->children[0]); - case slang_oper_variable_decl: + case SLANG_OPER_VARIABLE_DECL: return _slang_gen_declaration(A, oper); - case slang_oper_assign: + case SLANG_OPER_ASSIGN: return _slang_gen_assignment(A, oper); - case slang_oper_addassign: + case SLANG_OPER_ADDASSIGN: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "+=", oper, &oper->children[0]); return n; } - case slang_oper_subassign: + case SLANG_OPER_SUBASSIGN: { slang_ir_node *n; assert(oper->num_children == 2); @@ -2483,42 +2483,42 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } break; - case slang_oper_mulassign: + case SLANG_OPER_MULASSIGN: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "*=", oper, &oper->children[0]); return n; } - case slang_oper_divassign: + case SLANG_OPER_DIVASSIGN: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "/=", oper, &oper->children[0]); return n; } - case slang_oper_logicaland: + case SLANG_OPER_LOGICALAND: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_logical_and(A, oper); return n; } - case slang_oper_logicalor: + case SLANG_OPER_LOGICALOR: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_logical_or(A, oper); return n; } - case slang_oper_logicalxor: + case SLANG_OPER_LOGICALXOR: { slang_ir_node *n; assert(oper->num_children == 2); n = _slang_gen_function_call_name(A, "__logicalXor", oper, NULL); return n; } - case slang_oper_not: + case SLANG_OPER_NOT: { slang_ir_node *n; assert(oper->num_children == 1); @@ -2526,7 +2526,7 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } - case slang_oper_select: /* b ? x : y */ + case SLANG_OPER_SELECT: /* b ? x : y */ { slang_ir_node *n; assert(oper->num_children == 3); @@ -2534,20 +2534,20 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } - case slang_oper_asm: + case SLANG_OPER_ASM: return _slang_gen_asm(A, oper, NULL); - case slang_oper_call: + case SLANG_OPER_CALL: return _slang_gen_function_call_name(A, (const char *) oper->a_id, oper, NULL); - case slang_oper_return: + case SLANG_OPER_RETURN: return _slang_gen_return(A, oper); - case slang_oper_goto: + case SLANG_OPER_GOTO: return new_jump((char*) oper->a_id); - case slang_oper_label: + case SLANG_OPER_LABEL: return new_label((char*) oper->a_id); - case slang_oper_identifier: + case SLANG_OPER_IDENTIFIER: return _slang_gen_variable(A, oper); - case slang_oper_if: + case SLANG_OPER_IF: if (A->program->Target == GL_FRAGMENT_PROGRAM_ARB) { return _slang_gen_hl_if(A, oper); } @@ -2555,39 +2555,39 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) /* XXX update tnl executor */ return _slang_gen_if(A, oper); } - case slang_oper_field: + case SLANG_OPER_FIELD: return _slang_gen_field(A, oper); - case slang_oper_subscript: + case SLANG_OPER_SUBSCRIPT: return _slang_gen_subscript(A, oper); - case slang_oper_literal_float: + case SLANG_OPER_LITERAL_FLOAT: /* fall-through */ - case slang_oper_literal_int: + case SLANG_OPER_LITERAL_INT: /* fall-through */ - case slang_oper_literal_bool: + case SLANG_OPER_LITERAL_BOOL: return new_float_literal(oper->literal); - case slang_oper_postincrement: /* var++ */ + case SLANG_OPER_POSTINCREMENT: /* var++ */ { slang_ir_node *n; assert(oper->num_children == 1); n = _slang_gen_function_call_name(A, "__postIncr", oper, NULL); return n; } - case slang_oper_postdecrement: /* var-- */ + case SLANG_OPER_POSTDECREMENT: /* var-- */ { slang_ir_node *n; assert(oper->num_children == 1); n = _slang_gen_function_call_name(A, "__postDecr", oper, NULL); return n; } - case slang_oper_preincrement: /* ++var */ + case SLANG_OPER_PREINCREMENT: /* ++var */ { slang_ir_node *n; assert(oper->num_children == 1); n = _slang_gen_function_call_name(A, "++", oper, NULL); return n; } - case slang_oper_predecrement: /* --var */ + case SLANG_OPER_PREDECREMENT: /* --var */ { slang_ir_node *n; assert(oper->num_children == 1); @@ -2595,7 +2595,7 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } - case slang_oper_sequence: + case SLANG_OPER_SEQUENCE: { slang_ir_node *tree = NULL; GLuint i; @@ -2606,9 +2606,9 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return tree; } - case slang_oper_none: + case SLANG_OPER_NONE: return NULL; - case slang_oper_void: + case SLANG_OPER_VOID: return NULL; default: @@ -2658,7 +2658,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, store = _slang_new_ir_storage(PROGRAM_SAMPLER, samplerUniform, texIndex); if (dbg) printf("SAMPLER "); } - else if (var->type.qualifier == slang_qual_uniform) { + else if (var->type.qualifier == SLANG_QUAL_UNIFORM) { /* Uniform variable */ const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); if (prog) { @@ -2675,7 +2675,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } if (dbg) printf("UNIFORM "); } - else if (var->type.qualifier == slang_qual_varying) { + else if (var->type.qualifier == SLANG_QUAL_VARYING) { const GLint size = 4; /* XXX fix */ if (prog) { /* user-defined varying */ @@ -2684,7 +2684,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } else { /* pre-defined varying, like gl_Color or gl_TexCoord */ - if (type == slang_unit_fragment_builtin) { + if (type == SLANG_UNIT_FRAGMENT_BUILTIN) { GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); assert(index >= 0); store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); @@ -2693,7 +2693,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, else { GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); assert(index >= 0); - assert(type == slang_unit_vertex_builtin); + assert(type == SLANG_UNIT_VERTEX_BUILTIN); store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); assert(index < VERT_RESULT_MAX); } @@ -2701,7 +2701,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } if (dbg) printf("VARYING "); } - else if (var->type.qualifier == slang_qual_attribute) { + else if (var->type.qualifier == SLANG_QUAL_ATTRIBUTE) { if (prog) { /* user-defined vertex attribute */ const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); @@ -2721,27 +2721,27 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } if (dbg) printf("ATTRIB "); } - else if (var->type.qualifier == slang_qual_fixedinput) { + else if (var->type.qualifier == SLANG_QUAL_FIXEDINPUT) { GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); GLint size = 4; /* XXX? */ store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); if (dbg) printf("INPUT "); } - else if (var->type.qualifier == slang_qual_fixedoutput) { - if (type == slang_unit_vertex_builtin) { + else if (var->type.qualifier == SLANG_QUAL_FIXEDOUTPUT) { + if (type == SLANG_UNIT_VERTEX_BUILTIN) { GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); GLint size = 4; /* XXX? */ store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); } else { - assert(type == slang_unit_fragment_builtin); + assert(type == SLANG_UNIT_FRAGMENT_BUILTIN); GLint index = _slang_output_index(varName, GL_FRAGMENT_PROGRAM_ARB); GLint size = 4; /* XXX? */ store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); } if (dbg) printf("OUTPUT "); } - else if (var->type.qualifier == slang_qual_const && !prog) { + else if (var->type.qualifier == SLANG_QUAL_CONST && !prog) { /* pre-defined global constant, like gl_MaxLights */ const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size); diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index f73fccf436..f7aa297bfa 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -358,7 +358,7 @@ parse_array_len(slang_parse_ctx * C, slang_output_ctx * O, GLuint * len) /* evaluate compile-time expression which is array size */ _slang_simplify(&array_size, &space, C->atoms); - result = (array_size.type == slang_oper_literal_int); + result = (array_size.type == SLANG_OPER_LITERAL_INT); slang_operation_destruct(&array_size); return result; @@ -388,7 +388,7 @@ convert_to_array(slang_parse_ctx * C, slang_variable * var, { /* sized array - mark it as array, copy the specifier to the array element and * parse the expression */ - var->type.specifier.type = slang_spec_array; + var->type.specifier.type = SLANG_SPEC_ARRAY; var->type.specifier._array = (slang_type_specifier *) slang_alloc_malloc(sizeof(slang_type_specifier)); if (var->type.specifier._array == NULL) { @@ -540,25 +540,25 @@ parse_type_qualifier(slang_parse_ctx * C, slang_type_qualifier * qual) { switch (*C->I++) { case TYPE_QUALIFIER_NONE: - *qual = slang_qual_none; + *qual = SLANG_QUAL_NONE; break; case TYPE_QUALIFIER_CONST: - *qual = slang_qual_const; + *qual = SLANG_QUAL_CONST; break; case TYPE_QUALIFIER_ATTRIBUTE: - *qual = slang_qual_attribute; + *qual = SLANG_QUAL_ATTRIBUTE; break; case TYPE_QUALIFIER_VARYING: - *qual = slang_qual_varying; + *qual = SLANG_QUAL_VARYING; break; case TYPE_QUALIFIER_UNIFORM: - *qual = slang_qual_uniform; + *qual = SLANG_QUAL_UNIFORM; break; case TYPE_QUALIFIER_FIXEDOUTPUT: - *qual = slang_qual_fixedoutput; + *qual = SLANG_QUAL_FIXEDOUTPUT; break; case TYPE_QUALIFIER_FIXEDINPUT: - *qual = slang_qual_fixedinput; + *qual = SLANG_QUAL_FIXEDINPUT; break; default: return 0; @@ -598,78 +598,78 @@ parse_type_specifier(slang_parse_ctx * C, slang_output_ctx * O, { switch (*C->I++) { case TYPE_SPECIFIER_VOID: - spec->type = slang_spec_void; + spec->type = SLANG_SPEC_VOID; break; case TYPE_SPECIFIER_BOOL: - spec->type = slang_spec_bool; + spec->type = SLANG_SPEC_BOOL; break; case TYPE_SPECIFIER_BVEC2: - spec->type = slang_spec_bvec2; + spec->type = SLANG_SPEC_BVEC2; break; case TYPE_SPECIFIER_BVEC3: - spec->type = slang_spec_bvec3; + spec->type = SLANG_SPEC_BVEC3; break; case TYPE_SPECIFIER_BVEC4: - spec->type = slang_spec_bvec4; + spec->type = SLANG_SPEC_BVEC4; break; case TYPE_SPECIFIER_INT: - spec->type = slang_spec_int; + spec->type = SLANG_SPEC_INT; break; case TYPE_SPECIFIER_IVEC2: - spec->type = slang_spec_ivec2; + spec->type = SLANG_SPEC_IVEC2; break; case TYPE_SPECIFIER_IVEC3: - spec->type = slang_spec_ivec3; + spec->type = SLANG_SPEC_IVEC3; break; case TYPE_SPECIFIER_IVEC4: - spec->type = slang_spec_ivec4; + spec->type = SLANG_SPEC_IVEC4; break; case TYPE_SPECIFIER_FLOAT: - spec->type = slang_spec_float; + spec->type = SLANG_SPEC_FLOAT; break; case TYPE_SPECIFIER_VEC2: - spec->type = slang_spec_vec2; + spec->type = SLANG_SPEC_VEC2; break; case TYPE_SPECIFIER_VEC3: - spec->type = slang_spec_vec3; + spec->type = SLANG_SPEC_VEC3; break; case TYPE_SPECIFIER_VEC4: - spec->type = slang_spec_vec4; + spec->type = SLANG_SPEC_VEC4; break; case TYPE_SPECIFIER_MAT2: - spec->type = slang_spec_mat2; + spec->type = SLANG_SPEC_MAT2; break; case TYPE_SPECIFIER_MAT3: - spec->type = slang_spec_mat3; + spec->type = SLANG_SPEC_MAT3; break; case TYPE_SPECIFIER_MAT4: - spec->type = slang_spec_mat4; + spec->type = SLANG_SPEC_MAT4; break; case TYPE_SPECIFIER_SAMPLER1D: - spec->type = slang_spec_sampler1D; + spec->type = SLANG_SPEC_SAMPLER1D; break; case TYPE_SPECIFIER_SAMPLER2D: - spec->type = slang_spec_sampler2D; + spec->type = SLANG_SPEC_SAMPLER2D; break; case TYPE_SPECIFIER_SAMPLER3D: - spec->type = slang_spec_sampler3D; + spec->type = SLANG_SPEC_SAMPLER3D; break; case TYPE_SPECIFIER_SAMPLERCUBE: - spec->type = slang_spec_samplerCube; + spec->type = SLANG_SPEC_SAMPLERCUBE; break; case TYPE_SPECIFIER_SAMPLER1DSHADOW: - spec->type = slang_spec_sampler1DShadow; + spec->type = SLANG_SPEC_SAMPLER1DSHADOW; break; case TYPE_SPECIFIER_SAMPLER2DSHADOW: - spec->type = slang_spec_sampler2DShadow; + spec->type = SLANG_SPEC_SAMPLER2DSHADOW; break; case TYPE_SPECIFIER_STRUCT: - spec->type = slang_spec_struct; + spec->type = SLANG_SPEC_STRUCT; if (!parse_struct(C, O, &spec->_struct)) return 0; break; case TYPE_SPECIFIER_TYPENAME: - spec->type = slang_spec_struct; + spec->type = SLANG_SPEC_STRUCT; { slang_atom a_name; slang_struct *stru; @@ -817,7 +817,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, switch (*C->I++) { case OP_BLOCK_BEGIN_NO_NEW_SCOPE: /* parse child statements, do not create new variable scope */ - oper->type = slang_oper_block_no_new_scope; + oper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; while (*C->I != OP_END) if (!parse_child_operation(C, O, oper, 1)) return 0; @@ -828,7 +828,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, { slang_output_ctx o = *O; - oper->type = slang_oper_block_new_scope; + oper->type = SLANG_OPER_BLOCK_NEW_SCOPE; o.vars = oper->locals; while (*C->I != OP_END) if (!parse_child_operation(C, &o, oper, 1)) @@ -840,7 +840,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, /* local variable declaration, individual declarators are stored as * children identifiers */ - oper->type = slang_oper_block_no_new_scope; + oper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; { const unsigned int first_var = O->vars->num_variables; @@ -861,7 +861,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, } for (i = first_var; i < O->vars->num_variables; i++) { slang_operation *o = &oper->children[i - first_var]; - o->type = slang_oper_variable_decl; + o->type = SLANG_OPER_VARIABLE_DECL; o->locals->outer_scope = O->vars; o->a_id = O->vars->variables[i]->a_name; } @@ -872,7 +872,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, /* the __asm statement, parse the mnemonic and all its arguments * as expressions */ - oper->type = slang_oper_asm; + oper->type = SLANG_OPER_ASM; oper->a_id = parse_identifier(C); if (oper->a_id == SLANG_ATOM_NULL) return 0; @@ -883,26 +883,26 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, C->I++; break; case OP_BREAK: - oper->type = slang_oper_break; + oper->type = SLANG_OPER_BREAK; break; case OP_CONTINUE: - oper->type = slang_oper_continue; + oper->type = SLANG_OPER_CONTINUE; break; case OP_DISCARD: - oper->type = slang_oper_discard; + oper->type = SLANG_OPER_DISCARD; break; case OP_RETURN: - oper->type = slang_oper_return; + oper->type = SLANG_OPER_RETURN; if (!parse_child_operation(C, O, oper, 0)) return 0; break; case OP_EXPRESSION: - oper->type = slang_oper_expression; + oper->type = SLANG_OPER_EXPRESSION; if (!parse_child_operation(C, O, oper, 0)) return 0; break; case OP_IF: - oper->type = slang_oper_if; + oper->type = SLANG_OPER_IF; if (!parse_child_operation(C, O, oper, 0)) return 0; if (!parse_child_operation(C, O, oper, 1)) @@ -914,7 +914,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, { slang_output_ctx o = *O; - oper->type = slang_oper_while; + oper->type = SLANG_OPER_WHILE; o.vars = oper->locals; if (!parse_child_operation(C, &o, oper, 1)) return 0; @@ -923,7 +923,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, } break; case OP_DO: - oper->type = slang_oper_do; + oper->type = SLANG_OPER_DO; if (!parse_child_operation(C, O, oper, 1)) return 0; if (!parse_child_operation(C, O, oper, 0)) @@ -933,7 +933,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, { slang_output_ctx o = *O; - oper->type = slang_oper_for; + oper->type = SLANG_OPER_FOR; o.vars = oper->locals; if (!parse_child_operation(C, &o, oper, 1)) return 0; @@ -986,7 +986,7 @@ static int is_constructor_name(const char *name, slang_atom a_name, slang_struct_scope * structs) { - if (slang_type_specifier_type_from_string(name) != slang_spec_void) + if (slang_type_specifier_type_from_string(name) != SLANG_SPEC_VOID) return 1; return slang_struct_scope_find(structs, a_name, 1) != NULL; } @@ -1022,10 +1022,10 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, switch (op_code) { case OP_PUSH_VOID: - op->type = slang_oper_void; + op->type = SLANG_OPER_VOID; break; case OP_PUSH_BOOL: - op->type = slang_oper_literal_bool; + op->type = SLANG_OPER_LITERAL_BOOL; if (!parse_number(C, &number)) return 0; op->literal[0] = @@ -1035,7 +1035,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal_size = 1; break; case OP_PUSH_INT: - op->type = slang_oper_literal_int; + op->type = SLANG_OPER_LITERAL_INT; if (!parse_number(C, &number)) return 0; op->literal[0] = @@ -1045,7 +1045,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal_size = 1; break; case OP_PUSH_FLOAT: - op->type = slang_oper_literal_float; + op->type = SLANG_OPER_LITERAL_FLOAT; if (!parse_float(C, &op->literal[0])) return 0; op->literal[1] = @@ -1054,38 +1054,38 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, op->literal_size = 1; break; case OP_PUSH_IDENTIFIER: - op->type = slang_oper_identifier; + op->type = SLANG_OPER_IDENTIFIER; op->a_id = parse_identifier(C); if (op->a_id == SLANG_ATOM_NULL) return 0; break; case OP_SEQUENCE: - op->type = slang_oper_sequence; + op->type = SLANG_OPER_SEQUENCE; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_ASSIGN: - op->type = slang_oper_assign; + op->type = SLANG_OPER_ASSIGN; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_ADDASSIGN: - op->type = slang_oper_addassign; + op->type = SLANG_OPER_ADDASSIGN; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_SUBASSIGN: - op->type = slang_oper_subassign; + op->type = SLANG_OPER_SUBASSIGN; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_MULASSIGN: - op->type = slang_oper_mulassign; + op->type = SLANG_OPER_MULASSIGN; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_DIVASSIGN: - op->type = slang_oper_divassign; + op->type = SLANG_OPER_DIVASSIGN; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; @@ -1096,22 +1096,22 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, /*case OP_XORASSIGN: */ /*case OP_ANDASSIGN: */ case OP_SELECT: - op->type = slang_oper_select; + op->type = SLANG_OPER_SELECT; if (!handle_nary_expression(C, op, &ops, &num_ops, 3)) return 0; break; case OP_LOGICALOR: - op->type = slang_oper_logicalor; + op->type = SLANG_OPER_LOGICALOR; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_LOGICALXOR: - op->type = slang_oper_logicalxor; + op->type = SLANG_OPER_LOGICALXOR; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_LOGICALAND: - op->type = slang_oper_logicaland; + op->type = SLANG_OPER_LOGICALAND; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; @@ -1119,91 +1119,91 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, /*case OP_BITXOR: */ /*case OP_BITAND: */ case OP_EQUAL: - op->type = slang_oper_equal; + op->type = SLANG_OPER_EQUAL; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_NOTEQUAL: - op->type = slang_oper_notequal; + op->type = SLANG_OPER_NOTEQUAL; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_LESS: - op->type = slang_oper_less; + op->type = SLANG_OPER_LESS; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_GREATER: - op->type = slang_oper_greater; + op->type = SLANG_OPER_GREATER; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_LESSEQUAL: - op->type = slang_oper_lessequal; + op->type = SLANG_OPER_LESSequal; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_GREATEREQUAL: - op->type = slang_oper_greaterequal; + op->type = SLANG_OPER_GREATERequal; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; /*case OP_LSHIFT: */ /*case OP_RSHIFT: */ case OP_ADD: - op->type = slang_oper_add; + op->type = SLANG_OPER_ADD; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_SUBTRACT: - op->type = slang_oper_subtract; + op->type = SLANG_OPER_SUBTRACT; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_MULTIPLY: - op->type = slang_oper_multiply; + op->type = SLANG_OPER_MULTIPLY; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_DIVIDE: - op->type = slang_oper_divide; + op->type = SLANG_OPER_DIVIDE; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; /*case OP_MODULUS: */ case OP_PREINCREMENT: - op->type = slang_oper_preincrement; + op->type = SLANG_OPER_PREINCREMENT; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; case OP_PREDECREMENT: - op->type = slang_oper_predecrement; + op->type = SLANG_OPER_PREDECREMENT; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; case OP_PLUS: - op->type = slang_oper_plus; + op->type = SLANG_OPER_PLUS; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; case OP_MINUS: - op->type = slang_oper_minus; + op->type = SLANG_OPER_MINUS; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; case OP_NOT: - op->type = slang_oper_not; + op->type = SLANG_OPER_NOT; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; /*case OP_COMPLEMENT: */ case OP_SUBSCRIPT: - op->type = slang_oper_subscript; + op->type = SLANG_OPER_SUBSCRIPT; if (!handle_nary_expression(C, op, &ops, &num_ops, 2)) return 0; break; case OP_CALL: - op->type = slang_oper_call; + op->type = SLANG_OPER_CALL; op->a_id = parse_identifier(C); if (op->a_id == SLANG_ATOM_NULL) return 0; @@ -1224,7 +1224,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, } break; case OP_FIELD: - op->type = slang_oper_field; + op->type = SLANG_OPER_FIELD; op->a_id = parse_identifier(C); if (op->a_id == SLANG_ATOM_NULL) return 0; @@ -1232,12 +1232,12 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, return 0; break; case OP_POSTINCREMENT: - op->type = slang_oper_postincrement; + op->type = SLANG_OPER_POSTINCREMENT; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; case OP_POSTDECREMENT: - op->type = slang_oper_postdecrement; + op->type = SLANG_OPER_POSTDECREMENT; if (!handle_nary_expression(C, op, &ops, &num_ops, 1)) return 0; break; @@ -1273,23 +1273,23 @@ parse_parameter_declaration(slang_parse_ctx * C, slang_output_ctx * O, return 0; switch (*C->I++) { case PARAM_QUALIFIER_IN: - if (param->type.qualifier != slang_qual_const - && param->type.qualifier != slang_qual_none) { + if (param->type.qualifier != SLANG_QUAL_CONST + && param->type.qualifier != SLANG_QUAL_NONE) { slang_info_log_error(C->L, "Invalid type qualifier."); return 0; } break; case PARAM_QUALIFIER_OUT: - if (param->type.qualifier == slang_qual_none) - param->type.qualifier = slang_qual_out; + if (param->type.qualifier == SLANG_QUAL_NONE) + param->type.qualifier = SLANG_QUAL_OUT; else { slang_info_log_error(C->L, "Invalid type qualifier."); return 0; } break; case PARAM_QUALIFIER_INOUT: - if (param->type.qualifier == slang_qual_none) - param->type.qualifier = slang_qual_inout; + if (param->type.qualifier == SLANG_QUAL_NONE) + param->type.qualifier = SLANG_QUAL_INOUT; else { slang_info_log_error(C->L, "Invalid type qualifier."); return 0; @@ -1439,14 +1439,14 @@ parse_function_prototype(slang_parse_ctx * C, slang_output_ctx * O, return 0; switch (*C->I++) { case FUNCTION_ORDINARY: - func->kind = slang_func_ordinary; + func->kind = SLANG_FUNC_ORDINARY; func->header.a_name = parse_identifier(C); if (func->header.a_name == SLANG_ATOM_NULL) return 0; break; case FUNCTION_CONSTRUCTOR: - func->kind = slang_func_constructor; - if (func->header.type.specifier.type == slang_spec_struct) + func->kind = SLANG_FUNC_CONSTRUCTOR; + if (func->header.type.specifier.type == SLANG_SPEC_STRUCT) return 0; func->header.a_name = slang_atom_pool_atom(C->atoms, @@ -1458,7 +1458,7 @@ parse_function_prototype(slang_parse_ctx * C, slang_output_ctx * O, } break; case FUNCTION_OPERATOR: - func->kind = slang_func_operator; + func->kind = SLANG_FUNC_OPERATOR; func->header.a_name = parse_operator_name(C); if (func->header.a_name == SLANG_ATOM_NULL) return 0; @@ -1487,7 +1487,7 @@ parse_function_prototype(slang_parse_ctx * C, slang_output_ctx * O, assert(a_retVal); p->a_name = a_retVal; p->type = func->header.type; - p->type.qualifier = slang_qual_out; + p->type.qualifier = SLANG_QUAL_OUT; } /* function formal parameters and local variables share the same @@ -1546,7 +1546,7 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) /* construct the left side of assignment */ if (!slang_operation_construct(&op_id)) return GL_FALSE; - op_id.type = slang_oper_identifier; + op_id.type = SLANG_OPER_IDENTIFIER; op_id.a_id = var->a_name; /* put the variable into operation's scope */ @@ -1565,7 +1565,7 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) slang_operation_destruct(&op_id); return GL_FALSE; } - op_assign.type = slang_oper_assign; + op_assign.type = SLANG_OPER_ASSIGN; op_assign.children = (slang_operation *) slang_alloc_malloc(2 * sizeof(slang_operation)); if (op_assign.children == NULL) { @@ -1689,7 +1689,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, /* allocate global address space for a variable with a known size */ if (C->global_scope - && !(var->type.specifier.type == slang_spec_array + && !(var->type.specifier.type == SLANG_SPEC_ARRAY && var->array_len == 0)) { if (!calculate_var_size(C, O, var)) return GL_FALSE; @@ -1885,13 +1885,13 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, GLboolean success; GLuint maxRegs; - if (unit->type == slang_unit_fragment_builtin || - unit->type == slang_unit_fragment_shader) { + if (unit->type == SLANG_UNIT_FRAGMENT_BUILTIN || + unit->type == SLANG_UNIT_FRAGMENT_SHADER) { maxRegs = ctx->Const.FragmentProgram.MaxTemps; } else { - assert(unit->type == slang_unit_vertex_builtin || - unit->type == slang_unit_vertex_shader); + assert(unit->type == SLANG_UNIT_VERTEX_BUILTIN || + unit->type == SLANG_UNIT_VERTEX_SHADER); maxRegs = ctx->Const.VertexProgram.MaxTemps; } @@ -2055,8 +2055,8 @@ compile_object(grammar * id, const char *source, slang_code_object * object, } /* set shader type - the syntax is slightly different for different shaders */ - if (type == slang_unit_fragment_shader - || type == slang_unit_fragment_builtin) + if (type == SLANG_UNIT_FRAGMENT_SHADER + || type == SLANG_UNIT_FRAGMENT_BUILTIN) grammar_set_reg8(*id, (const byte *) "shader_type", 1); else grammar_set_reg8(*id, (const byte *) "shader_type", 2); @@ -2065,33 +2065,33 @@ compile_object(grammar * id, const char *source, slang_code_object * object, grammar_set_reg8(*id, (const byte *) "parsing_builtin", 1); /* if parsing user-specified shader, load built-in library */ - if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader) { + if (type == SLANG_UNIT_FRAGMENT_SHADER || type == SLANG_UNIT_VERTEX_SHADER) { /* compile core functionality first */ if (!compile_binary(slang_core_gc, &object->builtin[SLANG_BUILTIN_CORE], - slang_unit_fragment_builtin, infolog, + SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, NULL, NULL)) return GL_FALSE; /* compile common functions and variables, link to core */ if (!compile_binary(slang_common_builtin_gc, &object->builtin[SLANG_BUILTIN_COMMON], - slang_unit_fragment_builtin, infolog, NULL, + SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_CORE], NULL)) return GL_FALSE; /* compile target-specific functions and variables, link to common */ - if (type == slang_unit_fragment_shader) { + if (type == SLANG_UNIT_FRAGMENT_SHADER) { if (!compile_binary(slang_fragment_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET], - slang_unit_fragment_builtin, infolog, NULL, + SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_COMMON], NULL)) return GL_FALSE; } - else if (type == slang_unit_vertex_shader) { + else if (type == SLANG_UNIT_VERTEX_SHADER) { if (!compile_binary(slang_vertex_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET], - slang_unit_vertex_builtin, infolog, NULL, + SLANG_UNIT_VERTEX_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_COMMON], NULL)) return GL_FALSE; } @@ -2145,11 +2145,11 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) slang_unit_type type; if (shader->Type == GL_VERTEX_SHADER) { - type = slang_unit_vertex_shader; + type = SLANG_UNIT_VERTEX_SHADER; } else { assert(shader->Type == GL_FRAGMENT_SHADER); - type = slang_unit_fragment_shader; + type = SLANG_UNIT_FRAGMENT_SHADER; } /* XXX temporary hack */ diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index e7be7ef069..7abb92bd3b 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -39,17 +39,19 @@ extern "C" { typedef enum slang_unit_type_ { - slang_unit_fragment_shader, - slang_unit_vertex_shader, - slang_unit_fragment_builtin, - slang_unit_vertex_builtin + SLANG_UNIT_FRAGMENT_SHADER, + SLANG_UNIT_VERTEX_SHADER, + SLANG_UNIT_FRAGMENT_BUILTIN, + SLANG_UNIT_VERTEX_BUILTIN } slang_unit_type; + typedef struct slang_var_pool_ { - GLuint next_addr; + GLuint next_addr; } slang_var_pool; + typedef struct slang_code_unit_ { slang_variable_scope vars; @@ -59,6 +61,7 @@ typedef struct slang_code_unit_ struct slang_code_object_ *object; } slang_code_unit; + extern GLvoid _slang_code_unit_ctr (slang_code_unit *, struct slang_code_object_ *); diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c index 00a85c2e7d..9b0bdaf406 100644 --- a/src/mesa/shader/slang/slang_compile_function.c +++ b/src/mesa/shader/slang/slang_compile_function.c @@ -71,7 +71,7 @@ slang_fixup_save(slang_fixup_table *fixups, GLuint address) int slang_function_construct(slang_function * func) { - func->kind = slang_func_ordinary; + func->kind = SLANG_FUNC_ORDINARY; if (!slang_variable_construct(&func->header)) return 0; @@ -133,7 +133,7 @@ slang_function_scope_destruct(slang_function_scope * scope) GLboolean _slang_function_has_return_value(const slang_function *fun) { - return fun->header.type.specifier.type != slang_spec_void; + return fun->header.type.specifier.type != SLANG_SPEC_VOID; } @@ -179,7 +179,7 @@ slang_function_scope_find(slang_function_scope * funcs, slang_function * fun, slang_function *f = &funcs->functions[i]; const GLuint haveRetValue = 0; #if 0 - = (f->header.type.specifier.type != slang_spec_void); + = (f->header.type.specifier.type != SLANG_SPEC_VOID); #endif unsigned int j; diff --git a/src/mesa/shader/slang/slang_compile_function.h b/src/mesa/shader/slang/slang_compile_function.h index 99a6b2a034..b60b4a223f 100644 --- a/src/mesa/shader/slang/slang_compile_function.h +++ b/src/mesa/shader/slang/slang_compile_function.h @@ -36,9 +36,9 @@ struct slang_code_unit_; */ typedef enum slang_function_kind_ { - slang_func_ordinary, - slang_func_constructor, - slang_func_operator + SLANG_FUNC_ORDINARY, + SLANG_FUNC_CONSTRUCTOR, + SLANG_FUNC_OPERATOR } slang_function_kind; diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c index 51a64ca30b..288de2d4bf 100644 --- a/src/mesa/shader/slang/slang_compile_operation.c +++ b/src/mesa/shader/slang/slang_compile_operation.c @@ -38,7 +38,7 @@ GLboolean slang_operation_construct(slang_operation * oper) { - oper->type = slang_oper_none; + oper->type = SLANG_OPER_NONE; oper->children = NULL; oper->num_children = 0; oper->literal[0] = 0.0; diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h index 3f5b1bb8f3..a59f968456 100644 --- a/src/mesa/shader/slang/slang_compile_operation.h +++ b/src/mesa/shader/slang/slang_compile_operation.h @@ -37,70 +37,70 @@ extern "C" { */ typedef enum slang_operation_type_ { - slang_oper_none, - slang_oper_block_no_new_scope, /* "{" sequence "}" */ - slang_oper_block_new_scope, /* "{" sequence "}" */ - slang_oper_variable_decl, /* [type] [var] or [var] = [expr] */ - slang_oper_asm, - slang_oper_break, /* "break" statement */ - slang_oper_continue, /* "continue" statement */ - slang_oper_discard, /* "discard" (kill fragment) statement */ - slang_oper_return, /* "return" [expr] */ - slang_oper_goto, /* jump to label */ - slang_oper_label, /* a jump target */ - slang_oper_expression, /* [expr] */ - slang_oper_if, /* "if" [0] then [1] else [2] */ - slang_oper_while, /* "while" [cond] [body] */ - slang_oper_do, /* "do" [body] "while" [cond] */ - slang_oper_for, /* "for" [init] [while] [incr] [body] */ - slang_oper_void, /* nop */ - slang_oper_literal_bool, /* "true" or "false" */ - slang_oper_literal_int, /* integer literal */ - slang_oper_literal_float, /* float literal */ - slang_oper_identifier, /* var name, func name, etc */ - slang_oper_sequence, /* [expr] "," [expr] "," etc */ - slang_oper_assign, /* [var] "=" [expr] */ - slang_oper_addassign, /* [var] "+=" [expr] */ - slang_oper_subassign, /* [var] "-=" [expr] */ - slang_oper_mulassign, /* [var] "*=" [expr] */ - slang_oper_divassign, /* [var] "/=" [expr] */ - /*slang_oper_modassign, */ - /*slang_oper_lshassign, */ - /*slang_oper_rshassign, */ - /*slang_oper_orassign, */ - /*slang_oper_xorassign, */ - /*slang_oper_andassign, */ - slang_oper_select, /* [expr] "?" [expr] ":" [expr] */ - slang_oper_logicalor, /* [expr] "||" [expr] */ - slang_oper_logicalxor, /* [expr] "^^" [expr] */ - slang_oper_logicaland, /* [expr] "&&" [expr] */ - /*slang_oper_bitor, */ - /*slang_oper_bitxor, */ - /*slang_oper_bitand, */ - slang_oper_equal, /* [expr] "==" [expr] */ - slang_oper_notequal, /* [expr] "!=" [expr] */ - slang_oper_less, /* [expr] "<" [expr] */ - slang_oper_greater, /* [expr] ">" [expr] */ - slang_oper_lessequal, /* [expr] "<=" [expr] */ - slang_oper_greaterequal, /* [expr] ">=" [expr] */ - /*slang_oper_lshift, */ - /*slang_oper_rshift, */ - slang_oper_add, /* [expr] "+" [expr] */ - slang_oper_subtract, /* [expr] "-" [expr] */ - slang_oper_multiply, /* [expr] "*" [expr] */ - slang_oper_divide, /* [expr] "/" [expr] */ - /*slang_oper_modulus, */ - slang_oper_preincrement, /* "++" [var] */ - slang_oper_predecrement, /* "--" [var] */ - slang_oper_plus, /* "-" [expr] */ - slang_oper_minus, /* "+" [expr] */ - /*slang_oper_complement, */ - slang_oper_not, /* "!" [expr] */ - slang_oper_subscript, /* [expr] "[" [expr] "]" */ - slang_oper_call, /* [func name] [param] [param] [...] */ - slang_oper_field, /* i.e.: ".next" or ".xzy" or ".xxx" etc */ - slang_oper_postincrement, /* [var] "++" */ - slang_oper_postdecrement /* [var] "--" */ + SLANG_OPER_NONE, + SLANG_OPER_BLOCK_NO_NEW_SCOPE, /* "{" sequence "}" */ + SLANG_OPER_BLOCK_NEW_SCOPE, /* "{" sequence "}" */ + SLANG_OPER_VARIABLE_DECL, /* [type] [var] or [var] = [expr] */ + SLANG_OPER_ASM, + SLANG_OPER_BREAK, /* "break" statement */ + SLANG_OPER_CONTINUE, /* "continue" statement */ + SLANG_OPER_DISCARD, /* "discard" (kill fragment) statement */ + SLANG_OPER_RETURN, /* "return" [expr] */ + SLANG_OPER_GOTO, /* jump to label */ + SLANG_OPER_LABEL, /* a jump target */ + SLANG_OPER_EXPRESSION, /* [expr] */ + SLANG_OPER_IF, /* "if" [0] then [1] else [2] */ + SLANG_OPER_WHILE, /* "while" [cond] [body] */ + SLANG_OPER_DO, /* "do" [body] "while" [cond] */ + SLANG_OPER_FOR, /* "for" [init] [while] [incr] [body] */ + SLANG_OPER_VOID, /* nop */ + SLANG_OPER_LITERAL_BOOL, /* "true" or "false" */ + SLANG_OPER_LITERAL_INT, /* integer literal */ + SLANG_OPER_LITERAL_FLOAT, /* float literal */ + SLANG_OPER_IDENTIFIER, /* var name, func name, etc */ + SLANG_OPER_SEQUENCE, /* [expr] "," [expr] "," etc */ + SLANG_OPER_ASSIGN, /* [var] "=" [expr] */ + SLANG_OPER_ADDASSIGN, /* [var] "+=" [expr] */ + SLANG_OPER_SUBASSIGN, /* [var] "-=" [expr] */ + SLANG_OPER_MULASSIGN, /* [var] "*=" [expr] */ + SLANG_OPER_DIVASSIGN, /* [var] "/=" [expr] */ + /*SLANG_OPER_MODASSIGN, */ + /*SLANG_OPER_LSHASSIGN, */ + /*SLANG_OPER_RSHASSIGN, */ + /*SLANG_OPER_ORASSIGN, */ + /*SLANG_OPER_XORASSIGN, */ + /*SLANG_OPER_ANDASSIGN, */ + SLANG_OPER_SELECT, /* [expr] "?" [expr] ":" [expr] */ + SLANG_OPER_LOGICALOR, /* [expr] "||" [expr] */ + SLANG_OPER_LOGICALXOR, /* [expr] "^^" [expr] */ + SLANG_OPER_LOGICALAND, /* [expr] "&&" [expr] */ + /*SLANG_OPER_BITOR, */ + /*SLANG_OPER_BITXOR, */ + /*SLANG_OPER_BITAND, */ + SLANG_OPER_EQUAL, /* [expr] "==" [expr] */ + SLANG_OPER_NOTEQUAL, /* [expr] "!=" [expr] */ + SLANG_OPER_LESS, /* [expr] "<" [expr] */ + SLANG_OPER_GREATER, /* [expr] ">" [expr] */ + SLANG_OPER_LESSequal, /* [expr] "<=" [expr] */ + SLANG_OPER_GREATERequal, /* [expr] ">=" [expr] */ + /*SLANG_OPER_LSHIFT, */ + /*SLANG_OPER_RSHIFT, */ + SLANG_OPER_ADD, /* [expr] "+" [expr] */ + SLANG_OPER_SUBTRACT, /* [expr] "-" [expr] */ + SLANG_OPER_MULTIPLY, /* [expr] "*" [expr] */ + SLANG_OPER_DIVIDE, /* [expr] "/" [expr] */ + /*SLANG_OPER_MODULUS, */ + SLANG_OPER_PREINCREMENT, /* "++" [var] */ + SLANG_OPER_PREDECREMENT, /* "--" [var] */ + SLANG_OPER_PLUS, /* "-" [expr] */ + SLANG_OPER_MINUS, /* "+" [expr] */ + /*SLANG_OPER_COMPLEMENT, */ + SLANG_OPER_NOT, /* "!" [expr] */ + SLANG_OPER_SUBSCRIPT, /* [expr] "[" [expr] "]" */ + SLANG_OPER_CALL, /* [func name] [param] [param] [...] */ + SLANG_OPER_FIELD, /* i.e.: ".next" or ".xzy" or ".xxx" etc */ + SLANG_OPER_POSTINCREMENT, /* [var] "++" */ + SLANG_OPER_POSTDECREMENT /* [var] "--" */ } slang_operation_type; @@ -120,7 +120,7 @@ typedef struct slang_operation_ 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 */ + struct slang_function_ *fun; /**< If type == SLANG_OPER_CALL */ struct slang_variable_ *var; /**< If type == slang_oper_identier */ } slang_operation; diff --git a/src/mesa/shader/slang/slang_compile_struct.c b/src/mesa/shader/slang/slang_compile_struct.c index 5033a6cb10..5d876b248a 100644 --- a/src/mesa/shader/slang/slang_compile_struct.c +++ b/src/mesa/shader/slang/slang_compile_struct.c @@ -160,7 +160,7 @@ int slang_struct_equal (const slang_struct *x, const slang_struct *y) return 0; if (!slang_type_specifier_equal (&varx->type.specifier, &vary->type.specifier)) return 0; - if (varx->type.specifier.type == slang_spec_array) + if (varx->type.specifier.type == SLANG_SPEC_ARRAY) if (varx->array_len != vary->array_len) return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c index 25fbc21f82..450ae16323 100644 --- a/src/mesa/shader/slang/slang_compile_variable.c +++ b/src/mesa/shader/slang/slang_compile_variable.c @@ -40,29 +40,29 @@ typedef struct } type_specifier_type_name; static const type_specifier_type_name type_specifier_type_names[] = { - {"void", slang_spec_void}, - {"bool", slang_spec_bool}, - {"bvec2", slang_spec_bvec2}, - {"bvec3", slang_spec_bvec3}, - {"bvec4", slang_spec_bvec4}, - {"int", slang_spec_int}, - {"ivec2", slang_spec_ivec2}, - {"ivec3", slang_spec_ivec3}, - {"ivec4", slang_spec_ivec4}, - {"float", slang_spec_float}, - {"vec2", slang_spec_vec2}, - {"vec3", slang_spec_vec3}, - {"vec4", slang_spec_vec4}, - {"mat2", slang_spec_mat2}, - {"mat3", slang_spec_mat3}, - {"mat4", slang_spec_mat4}, - {"sampler1D", slang_spec_sampler1D}, - {"sampler2D", slang_spec_sampler2D}, - {"sampler3D", slang_spec_sampler3D}, - {"samplerCube", slang_spec_samplerCube}, - {"sampler1DShadow", slang_spec_sampler1DShadow}, - {"sampler2DShadow", slang_spec_sampler2DShadow}, - {NULL, slang_spec_void} + {"void", SLANG_SPEC_VOID}, + {"bool", SLANG_SPEC_BOOL}, + {"bvec2", SLANG_SPEC_BVEC2}, + {"bvec3", SLANG_SPEC_BVEC3}, + {"bvec4", SLANG_SPEC_BVEC4}, + {"int", SLANG_SPEC_INT}, + {"ivec2", SLANG_SPEC_IVEC2}, + {"ivec3", SLANG_SPEC_IVEC3}, + {"ivec4", SLANG_SPEC_IVEC4}, + {"float", SLANG_SPEC_FLOAT}, + {"vec2", SLANG_SPEC_VEC2}, + {"vec3", SLANG_SPEC_VEC3}, + {"vec4", SLANG_SPEC_VEC4}, + {"mat2", SLANG_SPEC_MAT2}, + {"mat3", SLANG_SPEC_MAT3}, + {"mat4", SLANG_SPEC_MAT4}, + {"sampler1D", SLANG_SPEC_SAMPLER1D}, + {"sampler2D", SLANG_SPEC_SAMPLER2D}, + {"sampler3D", SLANG_SPEC_SAMPLER3D}, + {"samplerCube", SLANG_SPEC_SAMPLERCUBE}, + {"sampler1DShadow", SLANG_SPEC_SAMPLER1DSHADOW}, + {"sampler2DShadow", SLANG_SPEC_SAMPLER2DSHADOW}, + {NULL, SLANG_SPEC_VOID} }; slang_type_specifier_type @@ -94,7 +94,7 @@ slang_type_specifier_type_to_string(slang_type_specifier_type type) int slang_fully_specified_type_construct(slang_fully_specified_type * type) { - type->qualifier = slang_qual_none; + type->qualifier = SLANG_QUAL_NONE; slang_type_specifier_ctr(&type->specifier); return 1; } @@ -333,49 +333,49 @@ static GLenum gl_type_from_specifier(const slang_type_specifier * type) { switch (type->type) { - case slang_spec_bool: + case SLANG_SPEC_BOOL: return GL_BOOL_ARB; - case slang_spec_bvec2: + case SLANG_SPEC_BVEC2: return GL_BOOL_VEC2_ARB; - case slang_spec_bvec3: + case SLANG_SPEC_BVEC3: return GL_BOOL_VEC3_ARB; - case slang_spec_bvec4: + case SLANG_SPEC_BVEC4: return GL_BOOL_VEC4_ARB; - case slang_spec_int: + case SLANG_SPEC_INT: return GL_INT; - case slang_spec_ivec2: + case SLANG_SPEC_IVEC2: return GL_INT_VEC2_ARB; - case slang_spec_ivec3: + case SLANG_SPEC_IVEC3: return GL_INT_VEC3_ARB; - case slang_spec_ivec4: + case SLANG_SPEC_IVEC4: return GL_INT_VEC4_ARB; - case slang_spec_float: + case SLANG_SPEC_FLOAT: return GL_FLOAT; - case slang_spec_vec2: + case SLANG_SPEC_VEC2: return GL_FLOAT_VEC2_ARB; - case slang_spec_vec3: + case SLANG_SPEC_VEC3: return GL_FLOAT_VEC3_ARB; - case slang_spec_vec4: + case SLANG_SPEC_VEC4: return GL_FLOAT_VEC4_ARB; - case slang_spec_mat2: + case SLANG_SPEC_MAT2: return GL_FLOAT_MAT2_ARB; - case slang_spec_mat3: + case SLANG_SPEC_MAT3: return GL_FLOAT_MAT3_ARB; - case slang_spec_mat4: + case SLANG_SPEC_MAT4: return GL_FLOAT_MAT4_ARB; - case slang_spec_sampler1D: + case SLANG_SPEC_SAMPLER1D: return GL_SAMPLER_1D_ARB; - case slang_spec_sampler2D: + case SLANG_SPEC_SAMPLER2D: return GL_SAMPLER_2D_ARB; - case slang_spec_sampler3D: + case SLANG_SPEC_SAMPLER3D: return GL_SAMPLER_3D_ARB; - case slang_spec_samplerCube: + case SLANG_SPEC_SAMPLERCUBE: return GL_SAMPLER_CUBE_ARB; - case slang_spec_sampler1DShadow: + case SLANG_SPEC_SAMPLER1DShadow: return GL_SAMPLER_1D_SHADOW_ARB; - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER2DShadow: return GL_SAMPLER_2D_SHADOW_ARB; - case slang_spec_array: + case SLANG_SPEC_ARRAy: return gl_type_from_specifier(type->_array); default: return GL_FLOAT; diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h index 841f9840a6..d12cfd7a40 100644 --- a/src/mesa/shader/slang/slang_compile_variable.h +++ b/src/mesa/shader/slang/slang_compile_variable.h @@ -32,15 +32,15 @@ extern "C" { typedef enum slang_type_qualifier_ { - slang_qual_none, - slang_qual_const, - slang_qual_attribute, - slang_qual_varying, - slang_qual_uniform, - slang_qual_out, - slang_qual_inout, - slang_qual_fixedoutput, /* internal */ - slang_qual_fixedinput /* internal */ + SLANG_QUAL_NONE, + SLANG_QUAL_CONST, + SLANG_QUAL_ATTRIBUTE, + SLANG_QUAL_VARYING, + SLANG_QUAL_UNIFORM, + SLANG_QUAL_OUT, + SLANG_QUAL_INOUT, + SLANG_QUAL_FIXEDOUTPUT, /* internal */ + SLANG_QUAL_FIXEDINPUT /* internal */ } slang_type_qualifier; extern slang_type_specifier_type @@ -75,7 +75,7 @@ typedef struct slang_variable_ { slang_fully_specified_type type; /**< Variable's data type */ slang_atom a_name; /**< The variable's name (char *) */ - GLuint array_len; /**< only if type == slang_spec_array */ + GLuint array_len; /**< only if type == SLANG_SPEC_ARRAy */ struct slang_operation_ *initializer; /**< Optional initializer code */ GLuint address; /**< Storage location */ GLuint size; /**< Variable's size in bytes */ diff --git a/src/mesa/shader/slang/slang_print.c b/src/mesa/shader/slang/slang_print.c index 7cfd87fb62..e53378e461 100644 --- a/src/mesa/shader/slang/slang_print.c +++ b/src/mesa/shader/slang/slang_print.c @@ -21,31 +21,31 @@ static void print_type(const slang_fully_specified_type *t) { switch (t->qualifier) { - case slang_qual_none: + case SLANG_QUAL_NONE: /*printf("");*/ break; - case slang_qual_const: + case SLANG_QUAL_CONST: printf("const "); break; - case slang_qual_attribute: + case SLANG_QUAL_ATTRIBUTE: printf("attrib "); break; - case slang_qual_varying: + case SLANG_QUAL_VARYING: printf("varying "); break; - case slang_qual_uniform: + case SLANG_QUAL_UNIFORM: printf("uniform "); break; - case slang_qual_out: + case SLANG_QUAL_OUT: printf("output "); break; - case slang_qual_inout: + case SLANG_QUAL_INOUT: printf("inout "); break; - case slang_qual_fixedoutput: + case SLANG_QUAL_FIXEDOUTPUT: printf("fixedoutput"); break; - case slang_qual_fixedinput: + case SLANG_QUAL_FIXEDINPUT: printf("fixedinput"); break; default: @@ -53,76 +53,76 @@ print_type(const slang_fully_specified_type *t) } switch (t->specifier.type) { - case slang_spec_void: + case SLANG_SPEC_VOID: printf("void"); break; - case slang_spec_bool: + case SLANG_SPEC_BOOL: printf("bool"); break; - case slang_spec_bvec2: + case SLANG_SPEC_BVEC2: printf("bvec2"); break; - case slang_spec_bvec3: + case SLANG_SPEC_BVEC3: printf("bvec3"); break; - case slang_spec_bvec4: + case SLANG_SPEC_BVEC4: printf("bvec4"); break; - case slang_spec_int: + case SLANG_SPEC_INT: printf("int"); break; - case slang_spec_ivec2: + case SLANG_SPEC_IVEC2: printf("ivec2"); break; - case slang_spec_ivec3: + case SLANG_SPEC_IVEC3: printf("ivec3"); break; - case slang_spec_ivec4: + case SLANG_SPEC_IVEC4: printf("ivec4"); break; - case slang_spec_float: + case SLANG_SPEC_FLOAT: printf("float"); break; - case slang_spec_vec2: + case SLANG_SPEC_VEC2: printf("vec2"); break; - case slang_spec_vec3: + case SLANG_SPEC_VEC3: printf("vec3"); break; - case slang_spec_vec4: + case SLANG_SPEC_VEC4: printf("vec4"); break; - case slang_spec_mat2: + case SLANG_SPEC_MAT2: printf("mat2"); break; - case slang_spec_mat3: + case SLANG_SPEC_MAT3: printf("mat3"); break; - case slang_spec_mat4: + case SLANG_SPEC_MAT4: printf("mat4"); break; - case slang_spec_sampler1D: + case SLANG_SPEC_SAMPLER1D: printf("sampler1D"); break; - case slang_spec_sampler2D: + case SLANG_SPEC_SAMPLER2D: printf("sampler2D"); break; - case slang_spec_sampler3D: + case SLANG_SPEC_SAMPLER3D: printf("sampler3D"); break; - case slang_spec_samplerCube: + case SLANG_SPEC_SAMPLERCUBE: printf("samplerCube"); break; - case slang_spec_sampler1DShadow: + case SLANG_SPEC_SAMPLER1DSHADOW: printf("sampler1DShadow"); break; - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER2DSHADOW: printf("sampler2DShadow"); break; - case slang_spec_struct: + case SLANG_SPEC_STRUCT: printf("struct"); break; - case slang_spec_array: + case SLANG_SPEC_ARRAY: printf("array"); break; default: @@ -219,12 +219,12 @@ slang_print_tree(const slang_operation *op, int indent) switch (op->type) { - case slang_oper_none: + case SLANG_OPER_NONE: spaces(indent); - printf("slang_oper_none\n"); + printf("SLANG_OPER_NONE\n"); break; - case slang_oper_block_no_new_scope: + case SLANG_OPER_BLOCK_NO_NEW_SCOPE: spaces(indent); printf("{ locals %p outer %p\n", (void*)op->locals, (void*)op->locals->outer_scope); print_generic(op, NULL, indent+3); @@ -232,7 +232,7 @@ slang_print_tree(const slang_operation *op, int indent) printf("}\n"); break; - case slang_oper_block_new_scope: + case SLANG_OPER_BLOCK_NEW_SCOPE: spaces(indent); printf("{{ // new scope locals %p\n", (void*)op->locals); print_generic(op, NULL, indent+3); @@ -240,7 +240,7 @@ slang_print_tree(const slang_operation *op, int indent) printf("}}\n"); break; - case slang_oper_variable_decl: + case SLANG_OPER_VARIABLE_DECL: assert(op->num_children == 0 || op->num_children == 1); { slang_variable *v; @@ -282,52 +282,52 @@ slang_print_tree(const slang_operation *op, int indent) } break; - case slang_oper_asm: + case SLANG_OPER_ASM: spaces(indent); printf("ASM: %s\n", (char*) op->a_id); print_generic(op, NULL, indent+3); break; - case slang_oper_break: + case SLANG_OPER_BREAK: spaces(indent); printf("BREAK\n"); break; - case slang_oper_continue: + case SLANG_OPER_CONTINUE: spaces(indent); printf("CONTINUE\n"); break; - case slang_oper_discard: + case SLANG_OPER_DISCARD: spaces(indent); printf("DISCARD\n"); break; - case slang_oper_return: + case SLANG_OPER_RETURN: spaces(indent); printf("RETURN\n"); if (op->num_children > 0) slang_print_tree(&op->children[0], indent + 3); break; - case slang_oper_goto: + case SLANG_OPER_GOTO: spaces(indent); printf("GOTO %s\n", (char *) op->a_id); break; - case slang_oper_label: + case SLANG_OPER_LABEL: spaces(indent); printf("LABEL %s\n", (char *) op->a_id); break; - case slang_oper_expression: + case SLANG_OPER_EXPRESSION: spaces(indent); printf("EXPR: locals %p\n", (void*) op->locals); - /*print_generic(op, "slang_oper_expression", indent);*/ + /*print_generic(op, "SLANG_OPER_EXPRESSION", indent);*/ slang_print_tree(&op->children[0], indent + 3); break; - case slang_oper_if: + case SLANG_OPER_IF: spaces(indent); printf("IF\n"); slang_print_tree(&op->children[0], indent + 3); @@ -341,7 +341,7 @@ slang_print_tree(const slang_operation *op, int indent) printf("ENDIF\n"); break; - case slang_oper_while: + case SLANG_OPER_WHILE: assert(op->num_children == 2); spaces(indent); printf("WHILE cond:\n"); @@ -351,7 +351,7 @@ slang_print_tree(const slang_operation *op, int indent) slang_print_tree(&op->children[1], indent + 3); break; - case slang_oper_do: + case SLANG_OPER_DO: spaces(indent); printf("DO body:\n"); slang_print_tree(&op->children[0], indent + 3); @@ -360,7 +360,7 @@ slang_print_tree(const slang_operation *op, int indent) slang_print_tree(&op->children[1], indent + 3); break; - case slang_oper_for: + case SLANG_OPER_FOR: spaces(indent); printf("FOR init:\n"); slang_print_tree(&op->children[0], indent + 3); @@ -380,32 +380,32 @@ slang_print_tree(const slang_operation *op, int indent) */ break; - case slang_oper_void: + case SLANG_OPER_VOID: spaces(indent); printf("(oper-void)\n"); break; - case slang_oper_literal_bool: + case SLANG_OPER_LITERAL_BOOL: spaces(indent); - /*printf("slang_oper_literal_bool\n");*/ + /*printf("SLANG_OPER_LITERAL_BOOL\n");*/ printf("%s\n", op->literal[0] ? "TRUE" : "FALSE"); break; - case slang_oper_literal_int: + case SLANG_OPER_LITERAL_INT: spaces(indent); - /*printf("slang_oper_literal_int\n");*/ + /*printf("SLANG_OPER_LITERAL_INT\n");*/ printf("(%d %d %d %d)\n", (int) op->literal[0], (int) op->literal[1], (int) op->literal[2], (int) op->literal[3]); break; - case slang_oper_literal_float: + case SLANG_OPER_LITERAL_FLOAT: spaces(indent); - /*printf("slang_oper_literal_float\n");*/ + /*printf("SLANG_OPER_LITERAL_FLOAT\n");*/ printf("(%f %f %f %f)\n", op->literal[0], op->literal[1], op->literal[2], op->literal[3]); break; - case slang_oper_identifier: + case SLANG_OPER_IDENTIFIER: spaces(indent); if (op->var && op->var->a_name) printf("VAR %s (in scope %p)\n", (char *) op->var->a_name, @@ -415,49 +415,49 @@ slang_print_tree(const slang_operation *op, int indent) (void *) find_scope(op->locals, op->a_id)); break; - case slang_oper_sequence: + case SLANG_OPER_SEQUENCE: print_generic(op, "COMMA-SEQ", indent+3); break; - case slang_oper_assign: + case SLANG_OPER_ASSIGN: spaces(indent); printf("ASSIGNMENT locals %p\n", (void*)op->locals); print_binary(op, ":=", indent); break; - case slang_oper_addassign: + case SLANG_OPER_ADDASSIGN: spaces(indent); printf("ASSIGN\n"); print_binary(op, "+=", indent); break; - case slang_oper_subassign: + case SLANG_OPER_SUBASSIGN: spaces(indent); printf("ASSIGN\n"); print_binary(op, "-=", indent); break; - case slang_oper_mulassign: + case SLANG_OPER_MULASSIGN: spaces(indent); printf("ASSIGN\n"); print_binary(op, "*=", indent); break; - case slang_oper_divassign: + case SLANG_OPER_DIVASSIGN: spaces(indent); printf("ASSIGN\n"); print_binary(op, "/=", indent); break; - /*slang_oper_modassign,*/ - /*slang_oper_lshassign,*/ - /*slang_oper_rshassign,*/ - /*slang_oper_orassign,*/ - /*slang_oper_xorassign,*/ - /*slang_oper_andassign,*/ - case slang_oper_select: + /*SLANG_OPER_MODASSIGN,*/ + /*SLANG_OPER_LSHASSIGN,*/ + /*SLANG_OPER_RSHASSIGN,*/ + /*SLANG_OPER_ORASSIGN,*/ + /*SLANG_OPER_XORASSIGN,*/ + /*SLANG_OPER_ANDASSIGN,*/ + case SLANG_OPER_SELECT: spaces(indent); - printf("slang_oper_select n=%d\n", op->num_children); + printf("SLANG_OPER_SELECT n=%d\n", op->num_children); assert(op->num_children == 3); slang_print_tree(&op->children[0], indent+3); spaces(indent); @@ -468,100 +468,100 @@ slang_print_tree(const slang_operation *op, int indent) slang_print_tree(&op->children[2], indent+3); break; - case slang_oper_logicalor: + case SLANG_OPER_LOGICALOR: print_binary(op, "||", indent); break; - case slang_oper_logicalxor: + case SLANG_OPER_LOGICALXOR: print_binary(op, "^^", indent); break; - case slang_oper_logicaland: + case SLANG_OPER_LOGICALAND: print_binary(op, "&&", indent); break; - /*slang_oper_bitor*/ - /*slang_oper_bitxor*/ - /*slang_oper_bitand*/ - case slang_oper_equal: + /*SLANG_OPER_BITOR*/ + /*SLANG_OPER_BITXOR*/ + /*SLANG_OPER_BITAND*/ + case SLANG_OPER_EQUAL: print_binary(op, "==", indent); break; - case slang_oper_notequal: + case SLANG_OPER_NOTEQUAL: print_binary(op, "!=", indent); break; - case slang_oper_less: + case SLANG_OPER_LESS: print_binary(op, "<", indent); break; - case slang_oper_greater: + case SLANG_OPER_GREATER: print_binary(op, ">", indent); break; - case slang_oper_lessequal: + case SLANG_OPER_LESSequal: print_binary(op, "<=", indent); break; - case slang_oper_greaterequal: + case SLANG_OPER_GREATERequal: print_binary(op, ">=", indent); break; - /*slang_oper_lshift*/ - /*slang_oper_rshift*/ - case slang_oper_add: + /*SLANG_OPER_LSHIFT*/ + /*SLANG_OPER_RSHIFT*/ + case SLANG_OPER_ADD: print_binary(op, "+", indent); break; - case slang_oper_subtract: + case SLANG_OPER_SUBTRACT: print_binary(op, "-", indent); break; - case slang_oper_multiply: + case SLANG_OPER_MULTIPLY: print_binary(op, "*", indent); break; - case slang_oper_divide: + case SLANG_OPER_DIVIDE: print_binary(op, "/", indent); break; - /*slang_oper_modulus*/ - case slang_oper_preincrement: + /*SLANG_OPER_MODULUS*/ + case SLANG_OPER_PREINCREMENT: spaces(indent); printf("PRE++\n"); slang_print_tree(&op->children[0], indent+3); break; - case slang_oper_predecrement: + case SLANG_OPER_PREDECREMENT: spaces(indent); printf("PRE--\n"); slang_print_tree(&op->children[0], indent+3); break; - case slang_oper_plus: + case SLANG_OPER_PLUS: spaces(indent); - printf("slang_oper_plus\n"); + printf("SLANG_OPER_PLUS\n"); break; - case slang_oper_minus: + case SLANG_OPER_MINUS: spaces(indent); - printf("slang_oper_minus\n"); + printf("SLANG_OPER_MINUS\n"); break; - /*slang_oper_complement*/ - case slang_oper_not: + /*SLANG_OPER_COMPLEMENT*/ + case SLANG_OPER_NOT: spaces(indent); printf("NOT\n"); slang_print_tree(&op->children[0], indent+3); break; - case slang_oper_subscript: + case SLANG_OPER_SUBSCRIPT: spaces(indent); - printf("slang_oper_subscript\n"); + printf("SLANG_OPER_SUBSCRIPT\n"); print_generic(op, NULL, indent+3); break; - case slang_oper_call: + case SLANG_OPER_CALL: #if 0 slang_function *fun = _slang_locate_function(A->space.funcs, oper->a_id, @@ -581,19 +581,19 @@ slang_print_tree(const slang_operation *op, int indent) printf(")\n"); break; - case slang_oper_field: + case SLANG_OPER_FIELD: spaces(indent); printf("FIELD %s of\n", (char*) op->a_id); slang_print_tree(&op->children[0], indent+3); break; - case slang_oper_postincrement: + case SLANG_OPER_POSTINCREMENT: spaces(indent); printf("POST++\n"); slang_print_tree(&op->children[0], indent+3); break; - case slang_oper_postdecrement: + case SLANG_OPER_POSTDECREMENT: spaces(indent); printf("POST--\n"); slang_print_tree(&op->children[0], indent+3); @@ -637,23 +637,23 @@ const char * slang_type_qual_string(slang_type_qualifier q) { switch (q) { - case slang_qual_none: + case SLANG_QUAL_NONE: return "none"; - case slang_qual_const: + case SLANG_QUAL_CONST: return "const"; - case slang_qual_attribute: + case SLANG_QUAL_ATTRIBUTE: return "attribute"; - case slang_qual_varying: + case SLANG_QUAL_VARYING: return "varying"; - case slang_qual_uniform: + case SLANG_QUAL_UNIFORM: return "uniform"; - case slang_qual_out: + case SLANG_QUAL_OUT: return "out"; - case slang_qual_inout: + case SLANG_QUAL_INOUT: return "inout"; - case slang_qual_fixedoutput: + case SLANG_QUAL_FIXEDOUTPUT: return "fixedoutput"; - case slang_qual_fixedinput: + case SLANG_QUAL_FIXEDINPUT: return "fixedinputk"; default: return "qual?"; @@ -665,53 +665,53 @@ static const char * slang_type_string(slang_type_specifier_type t) { switch (t) { - case slang_spec_void: + case SLANG_SPEC_VOID: return "void"; - case slang_spec_bool: + case SLANG_SPEC_BOOL: return "bool"; - case slang_spec_bvec2: + case SLANG_SPEC_BVEC2: return "bvec2"; - case slang_spec_bvec3: + case SLANG_SPEC_BVEC3: return "bvec3"; - case slang_spec_bvec4: + case SLANG_SPEC_BVEC4: return "bvec4"; - case slang_spec_int: + case SLANG_SPEC_INT: return "int"; - case slang_spec_ivec2: + case SLANG_SPEC_IVEC2: return "ivec2"; - case slang_spec_ivec3: + case SLANG_SPEC_IVEC3: return "ivec3"; - case slang_spec_ivec4: + case SLANG_SPEC_IVEC4: return "ivec4"; - case slang_spec_float: + case SLANG_SPEC_FLOAT: return "float"; - case slang_spec_vec2: + case SLANG_SPEC_VEC2: return "vec2"; - case slang_spec_vec3: + case SLANG_SPEC_VEC3: return "vec3"; - case slang_spec_vec4: + case SLANG_SPEC_VEC4: return "vec4"; - case slang_spec_mat2: + case SLANG_SPEC_MAT2: return "mat2"; - case slang_spec_mat3: + case SLANG_SPEC_MAT3: return "mat3"; - case slang_spec_mat4: + case SLANG_SPEC_MAT4: return "mat4"; - case slang_spec_sampler1D: + case SLANG_SPEC_SAMPLER1D: return "sampler1D"; - case slang_spec_sampler2D: + case SLANG_SPEC_SAMPLER2D: return "sampler2D"; - case slang_spec_sampler3D: + case SLANG_SPEC_SAMPLER3D: return "sampler3D"; - case slang_spec_samplerCube: + case SLANG_SPEC_SAMPLERCUBE: return "samplerCube"; - case slang_spec_sampler1DShadow: + case SLANG_SPEC_SAMPLER1DSHADOW: return "sampler1DShadow"; - case slang_spec_sampler2DShadow: + case SLANG_SPEC_SAMPLER2DSHADOW: return "sampler2DShadow"; - case slang_spec_struct: + case SLANG_SPEC_STRUCT: return "struct"; - case slang_spec_array: + case SLANG_SPEC_ARRAY: return "array"; default: return "type?"; diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 0e433281e8..07b4ae2760 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -97,7 +97,7 @@ _slang_simplify(slang_operation *oper, GLboolean isBool[4]; GLuint i, n; - if (oper->type == slang_oper_identifier) { + if (oper->type == SLANG_OPER_IDENTIFIER) { /* see if it's a named constant */ GLint value = _slang_lookup_constant((char *) oper->a_id); if (value >= 0) { @@ -105,7 +105,7 @@ _slang_simplify(slang_operation *oper, oper->literal[1] = oper->literal[2] = oper->literal[3] = value; - oper->type = slang_oper_literal_int; + oper->type = SLANG_OPER_LITERAL_INT; return; } } @@ -118,49 +118,49 @@ _slang_simplify(slang_operation *oper, /* examine children */ n = MIN2(oper->num_children, 4); for (i = 0; i < n; i++) { - isFloat[i] = (oper->children[i].type == slang_oper_literal_float || - oper->children[i].type == slang_oper_literal_int); - isBool[i] = (oper->children[i].type == slang_oper_literal_bool); + isFloat[i] = (oper->children[i].type == SLANG_OPER_LITERAL_FLOAT || + oper->children[i].type == SLANG_OPER_LITERAL_INT); + isBool[i] = (oper->children[i].type == SLANG_OPER_LITERAL_BOOL); } if (oper->num_children == 2 && isFloat[0] && isFloat[1]) { /* probably simple arithmetic */ switch (oper->type) { - case slang_oper_add: + case SLANG_OPER_ADD: for (i = 0; i < 4; i++) { 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; - case slang_oper_subtract: + case SLANG_OPER_SUBTRACT: for (i = 0; i < 4; i++) { 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; - case slang_oper_multiply: + case SLANG_OPER_MULTIPLY: for (i = 0; i < 4; i++) { 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; - case slang_oper_divide: + case SLANG_OPER_DIVIDE: for (i = 0; i < 4; i++) { 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; default: ; /* nothing */ @@ -169,19 +169,19 @@ _slang_simplify(slang_operation *oper, if (oper->num_children == 1 && isFloat[0]) { switch (oper->type) { - case slang_oper_minus: + 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; - case slang_oper_plus: + 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; default: ; /* nothing */ @@ -191,7 +191,7 @@ _slang_simplify(slang_operation *oper, if (oper->num_children == 2 && isBool[0] && isBool[1]) { /* simple boolean expression */ switch (oper->type) { - case slang_oper_logicaland: + case SLANG_OPER_LOGICALAND: for (i = 0; i < 4; i++) { const GLint a = oper->children[0].literal[i] ? 1 : 0; const GLint b = oper->children[1].literal[i] ? 1 : 0; @@ -199,9 +199,9 @@ _slang_simplify(slang_operation *oper, } oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); - oper->type = slang_oper_literal_bool; + oper->type = SLANG_OPER_LITERAL_BOOL; return; - case slang_oper_logicalor: + case SLANG_OPER_LOGICALOR: for (i = 0; i < 4; i++) { const GLint a = oper->children[0].literal[i] ? 1 : 0; const GLint b = oper->children[1].literal[i] ? 1 : 0; @@ -209,9 +209,9 @@ _slang_simplify(slang_operation *oper, } oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); - oper->type = slang_oper_literal_bool; + oper->type = SLANG_OPER_LITERAL_BOOL; return; - case slang_oper_logicalxor: + case SLANG_OPER_LOGICALXOR: for (i = 0; i < 4; i++) { const GLint a = oper->children[0].literal[i] ? 1 : 0; const GLint b = oper->children[1].literal[i] ? 1 : 0; @@ -219,7 +219,7 @@ _slang_simplify(slang_operation *oper, } oper->literal_size = oper->children[0].literal_size; slang_operation_destruct(oper); - oper->type = slang_oper_literal_bool; + oper->type = SLANG_OPER_LITERAL_BOOL; return; default: ; /* nothing */ @@ -229,7 +229,7 @@ _slang_simplify(slang_operation *oper, 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 (oper->type == SLANG_OPER_CALL) { if (strcmp((char *) oper->a_id, "vec4") == 0) { oper->literal[0] = oper->children[0].literal[0]; oper->literal[1] = oper->children[1].literal[0]; @@ -237,7 +237,7 @@ _slang_simplify(slang_operation *oper, oper->literal[3] = oper->children[3].literal[0]; oper->literal_size = 4; slang_operation_destruct(oper); - oper->type = slang_oper_literal_float; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; } } @@ -245,7 +245,7 @@ _slang_simplify(slang_operation *oper, if (oper->num_children == 3 && isFloat[0] && isFloat[1] && isFloat[2]) { /* vec3(flt, flt, flt) constructor */ - if (oper->type == slang_oper_call) { + 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]; @@ -253,7 +253,7 @@ _slang_simplify(slang_operation *oper, oper->literal[3] = oper->literal[2]; oper->literal_size = 3; slang_operation_destruct(oper); - oper->type = slang_oper_literal_float; + oper->type = SLANG_OPER_LITERAL_FLOAT; return; } } @@ -261,7 +261,7 @@ _slang_simplify(slang_operation *oper, if (oper->num_children == 2 && isFloat[0] && isFloat[1]) { /* vec2(flt, flt) constructor */ - if (oper->type == slang_oper_call) { + if (oper->type == SLANG_OPER_CALL) { if (strcmp((char *) oper->a_id, "vec2") == 0) { printf("SIMPLIFY vec2 constructor scope = %p\n", (void*) oper->locals); @@ -271,7 +271,7 @@ _slang_simplify(slang_operation *oper, 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; + oper->type = SLANG_OPER_LITERAL_FLOAT; assert(oper->num_children == 0); return; } @@ -305,7 +305,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (callOper->num_children != numParams) { /* number of arguments doesn't match number of parameters */ - if (fun->kind == slang_func_constructor) { + if (fun->kind == SLANG_FUNC_CONSTRUCTOR) { /* For constructor calls, we can try to unroll vector/matrix args * into individual floats/ints and try to match the function params. */ @@ -345,13 +345,13 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, /* replace arg[i+j] with subscript/index oper */ for (j = 0; j < argSz; j++) { - callOper->children[i + j].type = slang_oper_subscript; + callOper->children[i + j].type = SLANG_OPER_SUBSCRIPT; callOper->children[i + j].num_children = 2; callOper->children[i + j].children = slang_operation_new(2); slang_operation_copy(&callOper->children[i + j].children[0], &origArg); callOper->children[i + j].children[1].type - = slang_oper_literal_int; + = SLANG_OPER_LITERAL_INT; callOper->children[i + j].children[1].literal[0] = j; } @@ -408,7 +408,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, slang_operation_copy(child, &callOper->children[i]); child->locals->outer_scope = callOper->locals; - callOper->children[i].type = slang_oper_call; + callOper->children[i].type = SLANG_OPER_CALL; callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName); callOper->children[i].num_children = 1; callOper->children[i].children = child; diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c index 9f824371c5..74aff01aad 100644 --- a/src/mesa/shader/slang/slang_storage.c +++ b/src/mesa/shader/slang/slang_storage.c @@ -36,7 +36,7 @@ GLboolean slang_storage_array_construct(slang_storage_array * arr) { - arr->type = slang_stor_aggregate; + arr->type = SLANG_STORE_AGGREGATE; arr->aggregate = NULL; arr->length = 0; return GL_TRUE; @@ -110,7 +110,7 @@ aggregate_matrix(slang_storage_aggregate * agg, slang_storage_type basic_type, slang_storage_array *arr = slang_storage_aggregate_push_new(agg); if (arr == NULL) return GL_FALSE; - arr->type = slang_stor_aggregate; + arr->type = SLANG_STORE_AGGREGATE; arr->length = dimension; arr->aggregate = (slang_storage_aggregate *) @@ -155,54 +155,54 @@ _slang_aggregate_variable(slang_storage_aggregate * agg, slang_atom_pool * atoms) { switch (spec->type) { - case slang_spec_bool: - return aggregate_vector(agg, slang_stor_bool, 1); - case slang_spec_bvec2: - return aggregate_vector(agg, slang_stor_bool, 2); - case slang_spec_bvec3: - return aggregate_vector(agg, slang_stor_bool, 3); - case slang_spec_bvec4: - return aggregate_vector(agg, slang_stor_bool, 4); - case slang_spec_int: - return aggregate_vector(agg, slang_stor_int, 1); - case slang_spec_ivec2: - return aggregate_vector(agg, slang_stor_int, 2); - case slang_spec_ivec3: - return aggregate_vector(agg, slang_stor_int, 3); - case slang_spec_ivec4: - return aggregate_vector(agg, slang_stor_int, 4); - case slang_spec_float: - return aggregate_vector(agg, slang_stor_float, 1); - case slang_spec_vec2: - return aggregate_vector(agg, slang_stor_float, 2); - case slang_spec_vec3: - return aggregate_vector(agg, slang_stor_float, 3); - case slang_spec_vec4: - return aggregate_vector(agg, slang_stor_float, 4); - case slang_spec_mat2: - return aggregate_matrix(agg, slang_stor_float, 2); - case slang_spec_mat3: - return aggregate_matrix(agg, slang_stor_float, 3); - case slang_spec_mat4: - return aggregate_matrix(agg, slang_stor_float, 4); - case slang_spec_sampler1D: - case slang_spec_sampler2D: - case slang_spec_sampler3D: - case slang_spec_samplerCube: - case slang_spec_sampler1DShadow: - case slang_spec_sampler2DShadow: - return aggregate_vector(agg, slang_stor_int, 1); - case slang_spec_struct: + case SLANG_SPEC_BOOL: + return aggregate_vector(agg, SLANG_STORE_BOOL, 1); + case SLANG_SPEC_BVEC2: + return aggregate_vector(agg, SLANG_STORE_BOOL, 2); + case SLANG_SPEC_BVEC3: + return aggregate_vector(agg, SLANG_STORE_BOOL, 3); + case SLANG_SPEC_BVEC4: + return aggregate_vector(agg, SLANG_STORE_BOOL, 4); + case SLANG_SPEC_INT: + return aggregate_vector(agg, SLANG_STORE_INT, 1); + case SLANG_SPEC_IVEC2: + return aggregate_vector(agg, SLANG_STORE_INT, 2); + case SLANG_SPEC_IVEC3: + return aggregate_vector(agg, SLANG_STORE_INT, 3); + case SLANG_SPEC_IVEC4: + return aggregate_vector(agg, SLANG_STORE_INT, 4); + case SLANG_SPEC_FLOAT: + return aggregate_vector(agg, SLANG_STORE_FLOAT, 1); + case SLANG_SPEC_VEC2: + return aggregate_vector(agg, SLANG_STORE_FLOAT, 2); + case SLANG_SPEC_VEC3: + return aggregate_vector(agg, SLANG_STORE_FLOAT, 3); + case SLANG_SPEC_VEC4: + return aggregate_vector(agg, SLANG_STORE_FLOAT, 4); + case SLANG_SPEC_MAT2: + return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2); + case SLANG_SPEC_MAT3: + return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3); + case SLANG_SPEC_MAT4: + return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4); + case SLANG_SPEC_SAMPLER1D: + case SLANG_SPEC_SAMPLER2D: + case SLANG_SPEC_SAMPLER3D: + case SLANG_SPEC_SAMPLERCUBE: + case SLANG_SPEC_SAMPLER1DSHADOW: + case SLANG_SPEC_SAMPLER2DSHADOW: + return aggregate_vector(agg, SLANG_STORE_INT, 1); + case SLANG_SPEC_STRUCT: return aggregate_variables(agg, spec->_struct->fields, funcs, structs, vars, atoms); - case slang_spec_array: + case SLANG_SPEC_ARRAY: { slang_storage_array *arr; arr = slang_storage_aggregate_push_new(agg); if (arr == NULL) return GL_FALSE; - arr->type = slang_stor_aggregate; + arr->type = SLANG_STORE_AGGREGATE; arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc(sizeof(slang_storage_aggregate)); @@ -229,9 +229,9 @@ _slang_aggregate_variable(slang_storage_aggregate * agg, GLuint _slang_sizeof_type(slang_storage_type type) { - if (type == slang_stor_aggregate) + if (type == SLANG_STORE_AGGREGATE) return 0; - if (type == slang_stor_vec4) + if (type == SLANG_STORE_VEC4) return 4 * sizeof(GLfloat); return sizeof(GLfloat); } @@ -246,7 +246,7 @@ _slang_sizeof_aggregate(const slang_storage_aggregate * agg) slang_storage_array *arr = &agg->arrays[i]; GLuint element_size; - if (arr->type == slang_stor_aggregate) + if (arr->type == SLANG_STORE_AGGREGATE) element_size = _slang_sizeof_aggregate(arr->aggregate); else element_size = _slang_sizeof_type(arr->type); @@ -266,7 +266,7 @@ _slang_flatten_aggregate(slang_storage_aggregate * flat, GLuint j; for (j = 0; j < agg->arrays[i].length; j++) { - if (agg->arrays[i].type == slang_stor_aggregate) { + if (agg->arrays[i].type == SLANG_STORE_AGGREGATE) { if (!_slang_flatten_aggregate(flat, agg->arrays[i].aggregate)) return GL_FALSE; } @@ -274,9 +274,9 @@ _slang_flatten_aggregate(slang_storage_aggregate * flat, GLuint k, count; slang_storage_type type; - if (agg->arrays[i].type == slang_stor_vec4) { + if (agg->arrays[i].type == SLANG_STORE_VEC4) { count = 4; - type = slang_stor_float; + type = SLANG_STORE_FLOAT; } else { count = 1; diff --git a/src/mesa/shader/slang/slang_storage.h b/src/mesa/shader/slang/slang_storage.h index 5d756b5216..b02931fcc2 100644 --- a/src/mesa/shader/slang/slang_storage.h +++ b/src/mesa/shader/slang/slang_storage.h @@ -22,7 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined SLANG_STORAGE_H +#ifndef SLANG_STORAGE_H #define SLANG_STORAGE_H #include "slang_compile.h" @@ -47,12 +47,12 @@ typedef enum slang_storage_type_ { /* core */ - slang_stor_aggregate, - slang_stor_bool, - slang_stor_int, - slang_stor_float, + SLANG_STORE_AGGREGATE, + SLANG_STORE_BOOL, + SLANG_STORE_INT, + SLANG_STORE_FLOAT, /* vec4 */ - slang_stor_vec4 + SLANG_STORE_VEC4 } slang_storage_type; @@ -110,7 +110,7 @@ _slang_aggregate_variable(slang_storage_aggregate *agg, /* * Returns the size (in machine units) of the given storage type. - * It is an error to pass-in slang_stor_aggregate. + * It is an error to pass-in SLANG_STORE_AGGREGATE. * Returns 0 on error. */ extern GLuint @@ -135,5 +135,4 @@ _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *); -#endif - +#endif /* SLANG_STORAGE_H */ diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index 824bcc713f..bbcc1c740c 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -170,7 +170,7 @@ _slang_multiply_swizzles(slang_swizzle * dst, const slang_swizzle * left, GLvoid slang_type_specifier_ctr(slang_type_specifier * self) { - self->type = slang_spec_void; + self->type = SLANG_SPEC_VOID; self->_struct = NULL; self->_array = NULL; } @@ -196,7 +196,7 @@ slang_type_specifier_copy(slang_type_specifier * x, slang_type_specifier_ctr(&z); z.type = y->type; - if (z.type == slang_spec_struct) { + if (z.type == SLANG_SPEC_STRUCT) { z._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); if (z._struct == NULL) { slang_type_specifier_dtr(&z); @@ -212,7 +212,7 @@ slang_type_specifier_copy(slang_type_specifier * x, return GL_FALSE; } } - else if (z.type == slang_spec_array) { + else if (z.type == SLANG_SPEC_ARRAY) { z._array = (slang_type_specifier *) slang_alloc_malloc(sizeof(slang_type_specifier)); @@ -241,9 +241,9 @@ slang_type_specifier_equal(const slang_type_specifier * x, { if (x->type != y->type) return GL_FALSE; - if (x->type == slang_spec_struct) + if (x->type == SLANG_SPEC_STRUCT) return slang_struct_equal(x->_struct, y->_struct); - if (x->type == slang_spec_array) + if (x->type == SLANG_SPEC_ARRAY) return slang_type_specifier_equal(x->_array, y->_array); return GL_TRUE; } @@ -257,16 +257,16 @@ slang_type_specifier_compatible(const slang_type_specifier * x, const slang_type_specifier * y) { /* special case: float == int */ - if (x->type == slang_spec_int && y->type == slang_spec_float) { + if (x->type == SLANG_SPEC_INT && y->type == SLANG_SPEC_FLOAT) { return GL_TRUE; } /* XXX may need to add bool/int compatibility, etc */ if (x->type != y->type) return GL_FALSE; - if (x->type == slang_spec_struct) + if (x->type == SLANG_SPEC_STRUCT) return slang_struct_equal(x->_struct, y->_struct); - if (x->type == slang_spec_array) + if (x->type == SLANG_SPEC_ARRAY) return slang_type_specifier_compatible(x->_array, y->_array); return GL_TRUE; } @@ -341,93 +341,93 @@ _slang_typeof_operation_(const slang_operation * op, ti->is_swizzled = GL_FALSE; switch (op->type) { - case slang_oper_block_no_new_scope: - case slang_oper_block_new_scope: - case slang_oper_variable_decl: - case slang_oper_asm: - case slang_oper_break: - case slang_oper_continue: - case slang_oper_discard: - case slang_oper_return: - case slang_oper_if: - case slang_oper_while: - case slang_oper_do: - case slang_oper_for: - case slang_oper_void: - ti->spec.type = slang_spec_void; + case SLANG_OPER_BLOCK_NO_NEW_SCOPE: + case SLANG_OPER_BLOCK_NEW_SCOPE: + case SLANG_OPER_VARIABLE_DECL: + case SLANG_OPER_ASM: + case SLANG_OPER_BREAK: + case SLANG_OPER_CONTINUE: + case SLANG_OPER_DISCARD: + case SLANG_OPER_RETURN: + case SLANG_OPER_IF: + case SLANG_OPER_WHILE: + case SLANG_OPER_DO: + case SLANG_OPER_FOR: + case SLANG_OPER_VOID: + ti->spec.type = SLANG_SPEC_VOID; break; - case slang_oper_expression: - case slang_oper_assign: - case slang_oper_addassign: - case slang_oper_subassign: - case slang_oper_mulassign: - case slang_oper_divassign: - case slang_oper_preincrement: - case slang_oper_predecrement: + case SLANG_OPER_EXPRESSION: + case SLANG_OPER_ASSIGN: + case SLANG_OPER_ADDASSIGN: + case SLANG_OPER_SUBASSIGN: + case SLANG_OPER_MULASSIGN: + case SLANG_OPER_DIVASSIGN: + case SLANG_OPER_PREINCREMENT: + case SLANG_OPER_PREDECREMENT: if (!_slang_typeof_operation_(op->children, space, ti, atoms)) return GL_FALSE; break; - case slang_oper_literal_bool: + case SLANG_OPER_LITERAL_BOOL: if (op->literal_size == 1) - ti->spec.type = slang_spec_bool; + ti->spec.type = SLANG_SPEC_BOOL; else if (op->literal_size == 2) - ti->spec.type = slang_spec_bvec2; + ti->spec.type = SLANG_SPEC_BVEC2; else if (op->literal_size == 3) - ti->spec.type = slang_spec_bvec3; + ti->spec.type = SLANG_SPEC_BVEC3; else if (op->literal_size == 4) - ti->spec.type = slang_spec_bvec4; + 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; + ti->spec.type = SLANG_SPEC_BOOL; } break; - case slang_oper_logicalor: - case slang_oper_logicalxor: - case slang_oper_logicaland: - case slang_oper_equal: - case slang_oper_notequal: - case slang_oper_less: - case slang_oper_greater: - case slang_oper_lessequal: - case slang_oper_greaterequal: - case slang_oper_not: - ti->spec.type = slang_spec_bool; + case SLANG_OPER_LOGICALOR: + case SLANG_OPER_LOGICALXOR: + case SLANG_OPER_LOGICALAND: + case SLANG_OPER_EQUAL: + case SLANG_OPER_NOTEQUAL: + case SLANG_OPER_LESS: + case SLANG_OPER_GREATER: + case SLANG_OPER_LESSequal: + case SLANG_OPER_GREATERequal: + case SLANG_OPER_NOT: + ti->spec.type = SLANG_SPEC_BOOL; break; - case slang_oper_literal_int: + case SLANG_OPER_LITERAL_INT: if (op->literal_size == 1) - ti->spec.type = slang_spec_int; + ti->spec.type = SLANG_SPEC_INT; else if (op->literal_size == 2) - ti->spec.type = slang_spec_ivec2; + ti->spec.type = SLANG_SPEC_IVEC2; else if (op->literal_size == 3) - ti->spec.type = slang_spec_ivec3; + ti->spec.type = SLANG_SPEC_IVEC3; else if (op->literal_size == 4) - ti->spec.type = slang_spec_ivec4; + 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; + ti->spec.type = SLANG_SPEC_INT; } break; - case slang_oper_literal_float: + case SLANG_OPER_LITERAL_FLOAT: if (op->literal_size == 1) - ti->spec.type = slang_spec_float; + ti->spec.type = SLANG_SPEC_FLOAT; else if (op->literal_size == 2) - ti->spec.type = slang_spec_vec2; + ti->spec.type = SLANG_SPEC_VEC2; else if (op->literal_size == 3) - ti->spec.type = slang_spec_vec3; + ti->spec.type = SLANG_SPEC_VEC3; else if (op->literal_size == 4) - ti->spec.type = slang_spec_vec4; + 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; + ti->spec.type = SLANG_SPEC_FLOAT; } break; - case slang_oper_identifier: + case SLANG_OPER_IDENTIFIER: { slang_variable *var; var = _slang_locate_variable(op->locals, op->a_id, GL_TRUE); @@ -439,65 +439,65 @@ _slang_typeof_operation_(const slang_operation * op, ti->array_len = var->array_len; } break; - case slang_oper_sequence: + case SLANG_OPER_SEQUENCE: /* TODO: check [0] and [1] if they match */ if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) RETURN_NIL(); ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; - /*case slang_oper_modassign: */ - /*case slang_oper_lshassign: */ - /*case slang_oper_rshassign: */ - /*case slang_oper_orassign: */ - /*case slang_oper_xorassign: */ - /*case slang_oper_andassign: */ - case slang_oper_select: + /*case SLANG_OPER_MODASSIGN: */ + /*case SLANG_OPER_LSHASSIGN: */ + /*case SLANG_OPER_RSHASSIGN: */ + /*case SLANG_OPER_ORASSIGN: */ + /*case SLANG_OPER_XORASSIGN: */ + /*case SLANG_OPER_ANDASSIGN: */ + case SLANG_OPER_SELECT: /* TODO: check [1] and [2] if they match */ if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) RETURN_NIL(); ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; - /*case slang_oper_bitor: */ - /*case slang_oper_bitxor: */ - /*case slang_oper_bitand: */ - /*case slang_oper_lshift: */ - /*case slang_oper_rshift: */ - case slang_oper_add: + /*case SLANG_OPER_BITOR: */ + /*case SLANG_OPER_BITXOR: */ + /*case SLANG_OPER_BITAND: */ + /*case SLANG_OPER_LSHIFT: */ + /*case SLANG_OPER_RSHIFT: */ + case SLANG_OPER_ADD: if (!typeof_existing_function("+", op->children, 2, space, &ti->spec, atoms)) RETURN_NIL(); break; - case slang_oper_subtract: + case SLANG_OPER_SUBTRACT: if (!typeof_existing_function("-", op->children, 2, space, &ti->spec, atoms)) RETURN_NIL(); break; - case slang_oper_multiply: + case SLANG_OPER_MULTIPLY: if (!typeof_existing_function("*", op->children, 2, space, &ti->spec, atoms)) RETURN_NIL(); break; - case slang_oper_divide: + case SLANG_OPER_DIVIDE: if (!typeof_existing_function("/", op->children, 2, space, &ti->spec, atoms)) RETURN_NIL(); break; - /*case slang_oper_modulus: */ - case slang_oper_plus: + /*case SLANG_OPER_MODULUS: */ + case SLANG_OPER_PLUS: if (!_slang_typeof_operation_(op->children, space, ti, atoms)) RETURN_NIL(); ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; - case slang_oper_minus: + case SLANG_OPER_MINUS: if (!typeof_existing_function("-", op->children, 1, space, &ti->spec, atoms)) RETURN_NIL(); break; - /*case slang_oper_complement: */ - case slang_oper_subscript: + /*case SLANG_OPER_COMPLEMENT: */ + case SLANG_OPER_SUBSCRIPT: { slang_typeinfo _ti; @@ -508,7 +508,7 @@ _slang_typeof_operation_(const slang_operation * op, RETURN_NIL(); } ti->can_be_referenced = _ti.can_be_referenced; - if (_ti.spec.type == slang_spec_array) { + if (_ti.spec.type == SLANG_SPEC_ARRAY) { if (!slang_type_specifier_copy(&ti->spec, _ti.spec._array)) { slang_typeinfo_destruct(&_ti); RETURN_NIL(); @@ -525,7 +525,7 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo_destruct(&_ti); } break; - case slang_oper_call: + case SLANG_OPER_CALL: { GLboolean exists; @@ -536,7 +536,7 @@ _slang_typeof_operation_(const slang_operation * op, slang_struct *s = slang_struct_scope_find(space->structs, op->a_id, GL_TRUE); if (s != NULL) { - ti->spec.type = slang_spec_struct; + ti->spec.type = SLANG_SPEC_STRUCT; ti->spec._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); if (ti->spec._struct == NULL) @@ -555,14 +555,14 @@ _slang_typeof_operation_(const slang_operation * op, name = slang_atom_pool_id(atoms, op->a_id); type = slang_type_specifier_type_from_string(name); - if (type == slang_spec_void) + if (type == SLANG_SPEC_VOID) RETURN_ERROR2("function not found", name, 0); ti->spec.type = type; } } } break; - case slang_oper_field: + case SLANG_OPER_FIELD: { slang_typeinfo _ti; @@ -572,7 +572,7 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo_destruct(&_ti); RETURN_NIL(); } - if (_ti.spec.type == slang_spec_struct) { + if (_ti.spec.type == SLANG_SPEC_STRUCT) { slang_variable *field; field = _slang_locate_variable(_ti.spec._struct->fields, op->a_id, @@ -622,14 +622,14 @@ _slang_typeof_operation_(const slang_operation * op, break; case 2: switch (base) { - case slang_spec_float: - ti->spec.type = slang_spec_vec2; + case SLANG_SPEC_FLOAT: + ti->spec.type = SLANG_SPEC_VEC2; break; - case slang_spec_int: - ti->spec.type = slang_spec_ivec2; + case SLANG_SPEC_INT: + ti->spec.type = SLANG_SPEC_IVEC2; break; - case slang_spec_bool: - ti->spec.type = slang_spec_bvec2; + case SLANG_SPEC_BOOL: + ti->spec.type = SLANG_SPEC_BVEC2; break; default: break; @@ -637,14 +637,14 @@ _slang_typeof_operation_(const slang_operation * op, break; case 3: switch (base) { - case slang_spec_float: - ti->spec.type = slang_spec_vec3; + case SLANG_SPEC_FLOAT: + ti->spec.type = SLANG_SPEC_VEC3; break; - case slang_spec_int: - ti->spec.type = slang_spec_ivec3; + case SLANG_SPEC_INT: + ti->spec.type = SLANG_SPEC_IVEC3; break; - case slang_spec_bool: - ti->spec.type = slang_spec_bvec3; + case SLANG_SPEC_BOOL: + ti->spec.type = SLANG_SPEC_BVEC3; break; default: break; @@ -652,14 +652,14 @@ _slang_typeof_operation_(const slang_operation * op, break; case 4: switch (base) { - case slang_spec_float: - ti->spec.type = slang_spec_vec4; + case SLANG_SPEC_FLOAT: + ti->spec.type = SLANG_SPEC_VEC4; break; - case slang_spec_int: - ti->spec.type = slang_spec_ivec4; + case SLANG_SPEC_INT: + ti->spec.type = SLANG_SPEC_IVEC4; break; - case slang_spec_bool: - ti->spec.type = slang_spec_bvec4; + case SLANG_SPEC_BOOL: + ti->spec.type = SLANG_SPEC_BVEC4; break; default: break; @@ -672,8 +672,8 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo_destruct(&_ti); } break; - case slang_oper_postincrement: - case slang_oper_postdecrement: + case SLANG_OPER_POSTINCREMENT: + case SLANG_OPER_POSTDECREMENT: if (!_slang_typeof_operation_(op->children, space, ti, atoms)) RETURN_NIL(); ti->can_be_referenced = GL_FALSE; @@ -728,8 +728,8 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, * parameter to be l-value. */ if (!ti.can_be_referenced && - (f->parameters->variables[j]->type.qualifier == slang_qual_out || - f->parameters->variables[j]->type.qualifier == slang_qual_inout)) + (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT || + f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT)) break; } if (j == num_args) @@ -777,9 +777,9 @@ GLboolean _slang_type_is_matrix(slang_type_specifier_type ty) { switch (ty) { - case slang_spec_mat2: - case slang_spec_mat3: - case slang_spec_mat4: + case SLANG_SPEC_MAT2: + case SLANG_SPEC_MAT3: + case SLANG_SPEC_MAT4: return GL_TRUE; default: return GL_FALSE; @@ -795,15 +795,15 @@ GLboolean _slang_type_is_vector(slang_type_specifier_type ty) { switch (ty) { - case slang_spec_vec2: - case slang_spec_vec3: - case slang_spec_vec4: - case slang_spec_ivec2: - case slang_spec_ivec3: - case slang_spec_ivec4: - case slang_spec_bvec2: - case slang_spec_bvec3: - case slang_spec_bvec4: + case SLANG_SPEC_VEC2: + case SLANG_SPEC_VEC3: + case SLANG_SPEC_VEC4: + case SLANG_SPEC_IVEC2: + case SLANG_SPEC_IVEC3: + case SLANG_SPEC_IVEC4: + case SLANG_SPEC_BVEC2: + case SLANG_SPEC_BVEC3: + case SLANG_SPEC_BVEC4: return GL_TRUE; default: return GL_FALSE; @@ -818,29 +818,29 @@ slang_type_specifier_type _slang_type_base(slang_type_specifier_type ty) { switch (ty) { - case slang_spec_float: - case slang_spec_vec2: - case slang_spec_vec3: - case slang_spec_vec4: - return slang_spec_float; - case slang_spec_int: - case slang_spec_ivec2: - case slang_spec_ivec3: - case slang_spec_ivec4: - return slang_spec_int; - case slang_spec_bool: - case slang_spec_bvec2: - case slang_spec_bvec3: - case slang_spec_bvec4: - return slang_spec_bool; - case slang_spec_mat2: - return slang_spec_vec2; - case slang_spec_mat3: - return slang_spec_vec3; - case slang_spec_mat4: - return slang_spec_vec4; + case SLANG_SPEC_FLOAT: + case SLANG_SPEC_VEC2: + case SLANG_SPEC_VEC3: + case SLANG_SPEC_VEC4: + return SLANG_SPEC_FLOAT; + case SLANG_SPEC_INT: + case SLANG_SPEC_IVEC2: + case SLANG_SPEC_IVEC3: + case SLANG_SPEC_IVEC4: + return SLANG_SPEC_INT; + case SLANG_SPEC_BOOL: + case SLANG_SPEC_BVEC2: + case SLANG_SPEC_BVEC3: + case SLANG_SPEC_BVEC4: + return SLANG_SPEC_BOOL; + case SLANG_SPEC_MAT2: + return SLANG_SPEC_VEC2; + case SLANG_SPEC_MAT3: + return SLANG_SPEC_VEC3; + case SLANG_SPEC_MAT4: + return SLANG_SPEC_VEC4; default: - return slang_spec_void; + return SLANG_SPEC_VOID; } } @@ -852,24 +852,24 @@ GLuint _slang_type_dim(slang_type_specifier_type ty) { switch (ty) { - case slang_spec_float: - case slang_spec_int: - case slang_spec_bool: + case SLANG_SPEC_FLOAT: + case SLANG_SPEC_INT: + case SLANG_SPEC_BOOL: return 1; - case slang_spec_vec2: - case slang_spec_ivec2: - case slang_spec_bvec2: - case slang_spec_mat2: + case SLANG_SPEC_VEC2: + case SLANG_SPEC_IVEC2: + case SLANG_SPEC_BVEC2: + case SLANG_SPEC_MAT2: return 2; - case slang_spec_vec3: - case slang_spec_ivec3: - case slang_spec_bvec3: - case slang_spec_mat3: + case SLANG_SPEC_VEC3: + case SLANG_SPEC_IVEC3: + case SLANG_SPEC_BVEC3: + case SLANG_SPEC_MAT3: return 3; - case slang_spec_vec4: - case slang_spec_ivec4: - case slang_spec_bvec4: - case slang_spec_mat4: + case SLANG_SPEC_VEC4: + case SLANG_SPEC_IVEC4: + case SLANG_SPEC_BVEC4: + case SLANG_SPEC_MAT4: return 4; default: return 0; diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index 0f72fad090..3115b71e08 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -89,30 +89,30 @@ _slang_multiply_swizzles(slang_swizzle *, const slang_swizzle *, */ typedef enum slang_type_specifier_type_ { - slang_spec_void, - slang_spec_bool, - slang_spec_bvec2, - slang_spec_bvec3, - slang_spec_bvec4, - slang_spec_int, - slang_spec_ivec2, - slang_spec_ivec3, - slang_spec_ivec4, - slang_spec_float, - slang_spec_vec2, - slang_spec_vec3, - slang_spec_vec4, - slang_spec_mat2, - slang_spec_mat3, - slang_spec_mat4, - slang_spec_sampler1D, - slang_spec_sampler2D, - slang_spec_sampler3D, - slang_spec_samplerCube, - slang_spec_sampler1DShadow, - slang_spec_sampler2DShadow, - slang_spec_struct, - slang_spec_array + SLANG_SPEC_VOID, + SLANG_SPEC_BOOL, + SLANG_SPEC_BVEC2, + SLANG_SPEC_BVEC3, + SLANG_SPEC_BVEC4, + SLANG_SPEC_INT, + SLANG_SPEC_IVEC2, + SLANG_SPEC_IVEC3, + SLANG_SPEC_IVEC4, + SLANG_SPEC_FLOAT, + SLANG_SPEC_VEC2, + SLANG_SPEC_VEC3, + SLANG_SPEC_VEC4, + SLANG_SPEC_MAT2, + SLANG_SPEC_MAT3, + SLANG_SPEC_MAT4, + SLANG_SPEC_SAMPLER1D, + SLANG_SPEC_SAMPLER2D, + SLANG_SPEC_SAMPLER3D, + SLANG_SPEC_SAMPLERCUBE, + SLANG_SPEC_SAMPLER1DSHADOW, + SLANG_SPEC_SAMPLER2DSHADOW, + SLANG_SPEC_STRUCT, + SLANG_SPEC_ARRAY } slang_type_specifier_type; -- cgit v1.2.3 From c4ac5ac9d70bf89366f8d8798d038dbbc71d833f Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 26 Feb 2007 14:32:53 -0700 Subject: Overhaul of error handling. --- configs/linux-dri | 2 +- src/mesa/shader/slang/slang_codegen.c | 37 +++++----- src/mesa/shader/slang/slang_compile.c | 114 ++-------------------------- src/mesa/shader/slang/slang_compile.h | 13 ---- src/mesa/shader/slang/slang_emit.c | 18 +++-- src/mesa/shader/slang/slang_emit.h | 3 +- src/mesa/shader/slang/slang_preprocess.h | 23 +++--- src/mesa/shader/slang/slang_simplify.c | 6 +- src/mesa/shader/slang/slang_simplify.h | 3 +- src/mesa/shader/slang/slang_typeinfo.c | 123 +++++++++++++++++-------------- src/mesa/shader/slang/slang_typeinfo.h | 9 ++- src/mesa/sources | 2 +- 12 files changed, 129 insertions(+), 224 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/configs/linux-dri b/configs/linux-dri index 5f945a73f1..1a9146e299 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -67,4 +67,4 @@ WINDOW_SYSTEM=dri # gamma are missing because they have not been converted to use the new # interface. DRI_DIRS = i810 i915tex i915 i965 mach64 mga r128 r200 r300 radeon s3v \ - savage sis tdfx trident unichrome ffb + savage sis tdfx trident unichrome ffb nouveau diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d239a97500..efd330106b 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -47,7 +47,6 @@ #include "slang_typeinfo.h" #include "slang_codegen.h" #include "slang_compile.h" -#include "slang_error.h" #include "slang_label.h" #include "slang_simplify.h" #include "slang_emit.h" @@ -1154,7 +1153,7 @@ make_writemask(const char *field) */ static slang_ir_node * _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, - slang_operation *dest) + slang_operation *dest) { const slang_asm_info *info; slang_ir_node *kids[3], *n; @@ -1280,15 +1279,15 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, * Use 'name' to find the function to call */ fun = _slang_locate_function(A->space.funcs, atom, params, param_count, - &A->space, A->atoms); + &A->space, A->atoms, A->log); if (!fun) { /* A function with exactly the right parameters/types was not found. * Try adapting the parameters. */ fun = _slang_first_function(A->space.funcs, name); - if (!_slang_adapt_call(oper, fun, &A->space, A->atoms)) { - RETURN_ERROR2("Undefined function (or no matching parameters)", - name, 0); + if (!_slang_adapt_call(oper, fun, &A->space, A->atoms, A->log)) { + slang_info_log_error(A->log, "Undefined function '%s'", name); + return NULL; } assert(fun); } @@ -1361,7 +1360,8 @@ _slang_gen_while(slang_assemble_ctx * A, const slang_operation *oper) if (loop->BranchNode == 0 && isConst && constTrue) { /* infinite loop detected */ A->CurLoop = prevLoop; /* clean-up */ - RETURN_ERROR("Infinite loop detected!", 0); + slang_info_log_error(A->log, "Infinite loop detected!"); + return NULL; } /* pop loop, restore prev */ @@ -1816,7 +1816,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) assert(oper->num_children == 1); var = new_var(A, oper, oper->a_id); if (!var) { - RETURN_ERROR2("Undefined variable:", varName, 0); + slang_info_log_error(A->log, "undefined variable '%s'", varName); + return NULL; } /* XXX make copy of this initializer? */ rhs = _slang_gen_operation(A, &oper->children[0]); @@ -1829,7 +1830,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *var, *init, *rhs; var = new_var(A, oper, oper->a_id); if (!var) { - RETURN_ERROR2("Undefined variable:", varName, 0); + slang_info_log_error(A->log, "undefined variable '%s'", varName); + return NULL; } #if 0 /* XXX make copy of this initializer? */ @@ -1870,7 +1872,8 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) slang_atom aVar = oper->var ? oper->var->a_name : oper->a_id; slang_ir_node *n = new_var(A, oper, aVar); if (!n) { - RETURN_ERROR2("Undefined variable:", (char *) aVar, 0); + slang_info_log_error(A->log, "undefined variable '%s'", (char *) aVar); + return NULL; } return n; } @@ -2045,7 +2048,7 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; GLuint swizzle; if (!_slang_is_swizzle((char *) oper->a_id, rows, &swz)) { - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(A->log, "Bad swizzle"); } swizzle = MAKE_SWIZZLE4(swz.swizzle[0], swz.swizzle[1], @@ -2063,7 +2066,7 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) slang_ir_node *n; GLuint swizzle; if (!_slang_is_swizzle((char *) oper->a_id, rows, &swz)) { - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(A->log, "Bad swizzle"); } swizzle = MAKE_SWIZZLE4(swz.swizzle[0], swz.swizzle[1], @@ -2122,7 +2125,7 @@ _slang_gen_subscript(slang_assemble_ctx * A, slang_operation *oper) index = (GLint) oper->children[1].literal[0]; if (oper->children[1].type != SLANG_OPER_LITERAL_INT || index >= max) { - RETURN_ERROR("Invalid array index for vector type", 0); + slang_info_log_error(A->log, "Invalid array index for vector type"); } n = _slang_gen_operation(A, &oper->children[0]); @@ -2243,12 +2246,12 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return _slang_gen_while(A, oper); case SLANG_OPER_BREAK: if (!A->CurLoop) { - RETURN_ERROR("'break' not in loop", 0); + slang_info_log_error(A->log, "'break' not in loop"); } return new_break(A->CurLoop); case SLANG_OPER_CONTINUE: if (!A->CurLoop) { - RETURN_ERROR("'continue' not in loop", 0); + slang_info_log_error(A->log, "'continue' not in loop"); } return new_cont(A->CurLoop); case SLANG_OPER_DISCARD: @@ -2621,7 +2624,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, n = new_seq(n, init); } - success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE); + success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE, A->log); _slang_free_ir_tree(n); } @@ -2709,7 +2712,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #endif /* Emit program instructions */ - success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE); + success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE, A->log); _slang_free_ir_tree(n); /* free codegen context */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index a1cae5d338..1a4c7d31f1 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -37,8 +37,8 @@ #include "slang_compile.h" #include "slang_preprocess.h" #include "slang_storage.h" -#include "slang_error.h" #include "slang_emit.h" +#include "slang_log.h" #include "slang_vartable.h" #include "slang_simplify.h" @@ -115,110 +115,6 @@ _slang_code_object_dtr(slang_code_object * self) slang_atom_pool_destruct(&self->atompool); } -/* slang_info_log */ - -static char *out_of_memory = "Error: Out of memory.\n"; - -void -slang_info_log_construct(slang_info_log * log) -{ - log->text = NULL; - log->dont_free_text = 0; -} - -void -slang_info_log_destruct(slang_info_log * log) -{ - if (!log->dont_free_text) - slang_alloc_free(log->text); -} - -static int -slang_info_log_message(slang_info_log * log, const char *prefix, - const char *msg) -{ - GLuint size; - - if (log->dont_free_text) - return 0; - size = slang_string_length(msg) + 2; - if (prefix != NULL) - size += slang_string_length(prefix) + 2; - if (log->text != NULL) { - GLuint old_len = slang_string_length(log->text); - log->text = (char *) - slang_alloc_realloc(log->text, old_len + 1, old_len + size); - } - else { - log->text = (char *) (slang_alloc_malloc(size)); - if (log->text != NULL) - log->text[0] = '\0'; - } - if (log->text == NULL) - return 0; - if (prefix != NULL) { - slang_string_concat(log->text, prefix); - slang_string_concat(log->text, ": "); - } - slang_string_concat(log->text, msg); - slang_string_concat(log->text, "\n"); -#if 1 - abort(); /* XXX temporary */ -#endif - return 1; -} - -int -slang_info_log_print(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - return slang_info_log_message(log, NULL, buf); -} - -int -slang_info_log_error(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - if (slang_info_log_message(log, "Error", buf)) - return 1; - slang_info_log_memory(log); - return 0; -} - -int -slang_info_log_warning(slang_info_log * log, const char *msg, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, msg); - _mesa_vsprintf(buf, msg, va); - va_end(va); - if (slang_info_log_message(log, "Warning", buf)) - return 1; - slang_info_log_memory(log); - return 0; -} - -void -slang_info_log_memory(slang_info_log * log) -{ - if (!slang_info_log_message(log, "Error", "Out of memory.")) { - log->dont_free_text = 1; - log->text = out_of_memory; - } - abort(); /* XXX temporary */ -} /* slang_parse_ctx */ @@ -1838,8 +1734,7 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, A.space.vars = O->vars; A.program = O->program; A.vartable = O->vartable; - - _slang_reset_error(); + A.log = C->L; _slang_codegen_function(&A, *parsed_func_ret); } @@ -2002,7 +1897,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, slang_string_free(&preprocessed); grammar_get_last_error((byte *) (buf), sizeof(buf), &pos); slang_info_log_error(infolog, buf); - RETURN_ERROR("syntax error (possibly in library code)", 0); + /* syntax error (possibly in library code) */ } slang_string_free(&preprocessed); @@ -2175,7 +2070,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) success = compile_shader(ctx, &obj, type, &info_log, shader); - if (success) { + if (success && !info_log.text) { #if 0 slang_create_uniforms(&object->expdata, shader); _mesa_print_program(program); @@ -2183,6 +2078,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) #endif } else { + success = GL_FALSE; /* XXX more work on info log needed here */ if (info_log.text) { if (shader->InfoLog) { diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index 7abb92bd3b..086e2d8dc4 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -88,19 +88,6 @@ _slang_code_object_ctr (slang_code_object *); extern GLvoid _slang_code_object_dtr (slang_code_object *); -typedef struct slang_info_log_ -{ - char *text; - int dont_free_text; -} slang_info_log; - -void slang_info_log_construct (slang_info_log *); -void slang_info_log_destruct (slang_info_log *); -int slang_info_log_print (slang_info_log *, const char *, ...); -int slang_info_log_error (slang_info_log *, const char *, ...); -int slang_info_log_warning (slang_info_log *, const char *, ...); -void slang_info_log_memory (slang_info_log *); - extern GLboolean _slang_compile (GLcontext *ctx, struct gl_shader *shader); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index f5b6fb4d65..b0776e9340 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -45,7 +45,6 @@ #include "prog_print.h" #include "slang_builtin.h" #include "slang_emit.h" -#include "slang_error.h" #define PEEPHOLE_OPTIMIZATIONS 1 @@ -1421,14 +1420,20 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) assert(n->Store->Index < 0); if (!n->Var || n->Var->isTemp) { /* a nameless/temporary variable, will be freed after first use */ - if (!_slang_alloc_temp(emitInfo->vt, n->Store)) - RETURN_ERROR("Ran out of registers, too many temporaries", 0); + if (!_slang_alloc_temp(emitInfo->vt, n->Store)) { + slang_info_log_error(emitInfo->log, + "Ran out of registers, too many temporaries"); + return NULL; + } } else { /* a regular variable */ _slang_add_variable(emitInfo->vt, n->Var); - if (!_slang_alloc_var(emitInfo->vt, n->Store)) - RETURN_ERROR("Ran out of registers, too many variables", 0); + if (!_slang_alloc_var(emitInfo->vt, n->Store)) { + slang_info_log_error(emitInfo->log, + "Ran out of registers, too many variables"); + return NULL; + } /* printf("IR_VAR_DECL %s %d store %p\n", (char*) n->Var->a_name, n->Store->Index, (void*) n->Store); @@ -1530,7 +1535,8 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) n->Store->Size, &n->Store->Swizzle); if (n->Store->Index < 0) { - RETURN_ERROR("Ran out of space for constants.", 0); + slang_info_log_error(emitInfo->log, "Ran out of space for constants"); + return NULL; } return NULL; diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h index 1b792402da..13ba6d7d6c 100644 --- a/src/mesa/shader/slang/slang_emit.h +++ b/src/mesa/shader/slang/slang_emit.h @@ -42,7 +42,8 @@ _slang_new_ir_storage(enum register_file file, GLint index, GLint size); extern GLboolean _slang_emit_code(slang_ir_node *n, slang_var_table *vartable, - struct gl_program *prog, GLboolean withEnd); + struct gl_program *prog, GLboolean withEnd, + slang_info_log *log); #endif /* SLANG_EMIT_H */ diff --git a/src/mesa/shader/slang/slang_preprocess.h b/src/mesa/shader/slang/slang_preprocess.h index f83e6e6e3f..d8eb12e4ff 100644 --- a/src/mesa/shader/slang/slang_preprocess.h +++ b/src/mesa/shader/slang/slang_preprocess.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.6 + * Version: 6.5.3 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,24 +22,19 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined SLANG_PREPROCESS_H +#ifndef SLANG_PREPROCESS_H #define SLANG_PREPROCESS_H #include "slang_compile.h" +#include "slang_log.h" -#if defined __cplusplus -extern "C" { -#endif -GLboolean +extern GLboolean _slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *); -GLboolean -_slang_preprocess_directives (slang_string *output, const char *input, slang_info_log *); +extern GLboolean +_slang_preprocess_directives (slang_string *output, const char *input, + slang_info_log *); -#ifdef __cplusplus -} -#endif - -#endif +#endif /* SLANG_PREPROCESS_H */ diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 07b4ae2760..87b117874f 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -292,7 +292,7 @@ _slang_simplify(slang_operation *oper, GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, const slang_name_space * space, - slang_atom_pool * atoms) + slang_atom_pool * atoms, slang_info_log *log) { const GLboolean haveRetValue = _slang_function_has_return_value(fun); const int numParams = fun->param_count - haveRetValue; @@ -317,7 +317,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, - &argType, atoms)) { + &argType, atoms, log)) { slang_typeinfo_destruct(&argType); return GL_FALSE; } @@ -392,7 +392,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (!slang_typeinfo_construct(&argType)) return GL_FALSE; if (!_slang_typeof_operation_(&callOper->children[i], space, - &argType, atoms)) { + &argType, atoms, log)) { slang_typeinfo_destruct(&argType); return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index d6979a800a..b3840ee9df 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -16,8 +16,7 @@ _slang_simplify(slang_operation *oper, extern GLboolean _slang_adapt_call(slang_operation *callOper, const slang_function *fun, const slang_name_space * space, - slang_atom_pool * atoms); - + slang_atom_pool * atoms, slang_info_log *log); #endif /* SLANG_SIMPLIFY_H */ diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index bbcc1c740c..fe3834994d 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -31,7 +31,7 @@ #include "imports.h" #include "slang_typeinfo.h" #include "slang_compile.h" -#include "slang_error.h" +#include "slang_log.h" #include "prog_instruction.h" @@ -302,14 +302,15 @@ typeof_existing_function(const char *name, const slang_operation * params, GLuint num_params, const slang_name_space * space, slang_type_specifier * spec, - slang_atom_pool * atoms) + slang_atom_pool * atoms, + slang_info_log *log) { slang_atom atom; GLboolean exists; atom = slang_atom_pool_atom(atoms, name); if (!_slang_typeof_function(atom, params, num_params, space, spec, - &exists, atoms)) + &exists, atoms, log)) return GL_FALSE; return exists; } @@ -319,7 +320,7 @@ _slang_typeof_operation(const slang_assemble_ctx * A, const slang_operation * op, slang_typeinfo * ti) { - return _slang_typeof_operation_(op, &A->space, ti, A->atoms); + return _slang_typeof_operation_(op, &A->space, ti, A->atoms, A->log); } @@ -335,7 +336,8 @@ GLboolean _slang_typeof_operation_(const slang_operation * op, const slang_name_space * space, slang_typeinfo * ti, - slang_atom_pool * atoms) + slang_atom_pool * atoms, + slang_info_log *log) { ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; @@ -364,7 +366,7 @@ _slang_typeof_operation_(const slang_operation * op, case SLANG_OPER_DIVASSIGN: case SLANG_OPER_PREINCREMENT: case SLANG_OPER_PREDECREMENT: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) return GL_FALSE; break; case SLANG_OPER_LITERAL_BOOL: @@ -431,18 +433,24 @@ _slang_typeof_operation_(const slang_operation * op, { slang_variable *var; var = _slang_locate_variable(op->locals, op->a_id, GL_TRUE); - if (var == NULL) - RETURN_ERROR2("undefined variable", (char *) op->a_id, 0); - if (!slang_type_specifier_copy(&ti->spec, &var->type.specifier)) - RETURN_OUT_OF_MEMORY(); + if (!var) { + slang_info_log_error(log, "undefined variable '%s'", + (char *) op->a_id); + return GL_FALSE; + } + if (!slang_type_specifier_copy(&ti->spec, &var->type.specifier)) { + slang_info_log_memory(log); + return GL_FALSE; + } ti->can_be_referenced = GL_TRUE; ti->array_len = var->array_len; } break; case SLANG_OPER_SEQUENCE: /* TODO: check [0] and [1] if they match */ - if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms, log)) { + return GL_FALSE; + } ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; @@ -454,8 +462,9 @@ _slang_typeof_operation_(const slang_operation * op, /*case SLANG_OPER_ANDASSIGN: */ case SLANG_OPER_SELECT: /* TODO: check [1] and [2] if they match */ - if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(&op->children[1], space, ti, atoms, log)) { + return GL_FALSE; + } ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; @@ -466,35 +475,35 @@ _slang_typeof_operation_(const slang_operation * op, /*case SLANG_OPER_RSHIFT: */ case SLANG_OPER_ADD: if (!typeof_existing_function("+", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_SUBTRACT: if (!typeof_existing_function("-", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_MULTIPLY: if (!typeof_existing_function("*", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; case SLANG_OPER_DIVIDE: if (!typeof_existing_function("/", op->children, 2, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; /*case SLANG_OPER_MODULUS: */ case SLANG_OPER_PLUS: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) + return GL_FALSE; ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; case SLANG_OPER_MINUS: if (!typeof_existing_function("-", op->children, 1, space, - &ti->spec, atoms)) - RETURN_NIL(); + &ti->spec, atoms, log)) + return GL_FALSE; break; /*case SLANG_OPER_COMPLEMENT: */ case SLANG_OPER_SUBSCRIPT: @@ -502,23 +511,24 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo _ti; if (!slang_typeinfo_construct(&_ti)) - RETURN_NIL(); - if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { + return GL_FALSE; + if (!_slang_typeof_operation_(op->children, space, &_ti, atoms, log)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } ti->can_be_referenced = _ti.can_be_referenced; if (_ti.spec.type == SLANG_SPEC_ARRAY) { if (!slang_type_specifier_copy(&ti->spec, _ti.spec._array)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } } else { if (!_slang_type_is_vector(_ti.spec.type) && !_slang_type_is_matrix(_ti.spec.type)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("cannot index a non-array type", 0); + slang_info_log_error(log, "cannot index a non-array type"); + return GL_FALSE; } ti->spec.type = _slang_type_base(_ti.spec.type); } @@ -530,8 +540,8 @@ _slang_typeof_operation_(const slang_operation * op, GLboolean exists; if (!_slang_typeof_function(op->a_id, op->children, op->num_children, - space, &ti->spec, &exists, atoms)) - RETURN_NIL(); + space, &ti->spec, &exists, atoms, log)) + return GL_FALSE; if (!exists) { slang_struct *s = slang_struct_scope_find(space->structs, op->a_id, GL_TRUE); @@ -540,14 +550,14 @@ _slang_typeof_operation_(const slang_operation * op, ti->spec._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); if (ti->spec._struct == NULL) - RETURN_NIL(); + return GL_FALSE; if (!slang_struct_construct(ti->spec._struct)) { slang_alloc_free(ti->spec._struct); ti->spec._struct = NULL; - RETURN_NIL(); + return GL_FALSE; } if (!slang_struct_copy(ti->spec._struct, s)) - RETURN_NIL(); + return GL_FALSE; } else { const char *name; @@ -555,8 +565,10 @@ _slang_typeof_operation_(const slang_operation * op, name = slang_atom_pool_id(atoms, op->a_id); type = slang_type_specifier_type_from_string(name); - if (type == SLANG_SPEC_VOID) - RETURN_ERROR2("function not found", name, 0); + if (type == SLANG_SPEC_VOID) { + slang_info_log_error(log, "undefined function '%s'", name); + return GL_FALSE; + } ti->spec.type = type; } } @@ -567,10 +579,10 @@ _slang_typeof_operation_(const slang_operation * op, slang_typeinfo _ti; if (!slang_typeinfo_construct(&_ti)) - RETURN_NIL(); - if (!_slang_typeof_operation_(op->children, space, &_ti, atoms)) { + return GL_FALSE; + if (!_slang_typeof_operation_(op->children, space, &_ti, atoms, log)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } if (_ti.spec.type == SLANG_SPEC_STRUCT) { slang_variable *field; @@ -579,11 +591,11 @@ _slang_typeof_operation_(const slang_operation * op, GL_FALSE); if (field == NULL) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } if (!slang_type_specifier_copy(&ti->spec, &field->type.specifier)) { slang_typeinfo_destruct(&_ti); - RETURN_NIL(); + return GL_FALSE; } ti->can_be_referenced = _ti.can_be_referenced; } @@ -593,17 +605,19 @@ _slang_typeof_operation_(const slang_operation * op, slang_type_specifier_type base; /* determine the swizzle of the field expression */ -#if 000 +#if 000 /*XXX re-enable? */ if (!_slang_type_is_vector(_ti.spec.type)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("Can't swizzle scalar expression", 0); + slang_info_log_error(log, "Can't swizzle scalar expression"); + return GL_FALSE; } #endif rows = _slang_type_dim(_ti.spec.type); swizzle = slang_atom_pool_id(atoms, op->a_id); if (!_slang_is_swizzle(swizzle, rows, &ti->swz)) { slang_typeinfo_destruct(&_ti); - RETURN_ERROR("Bad swizzle", 0); + slang_info_log_error(log, "bad swizzle '%s'", swizzle); + return GL_FALSE; } ti->is_swizzled = GL_TRUE; ti->can_be_referenced = _ti.can_be_referenced @@ -674,13 +688,13 @@ _slang_typeof_operation_(const slang_operation * op, break; case SLANG_OPER_POSTINCREMENT: case SLANG_OPER_POSTDECREMENT: - if (!_slang_typeof_operation_(op->children, space, ti, atoms)) - RETURN_NIL(); + if (!_slang_typeof_operation_(op->children, space, ti, atoms, log)) + return GL_FALSE; ti->can_be_referenced = GL_FALSE; ti->is_swizzled = GL_FALSE; break; default: - RETURN_NIL(); + return GL_FALSE; } return GL_TRUE; @@ -693,7 +707,8 @@ _slang_typeof_operation_(const slang_operation * op, slang_function * _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, const slang_operation * args, GLuint num_args, - const slang_name_space * space, slang_atom_pool * atoms) + const slang_name_space * space, slang_atom_pool * atoms, + slang_info_log *log) { GLuint i; @@ -713,7 +728,7 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, if (!slang_typeinfo_construct(&ti)) return NULL; - if (!_slang_typeof_operation_(&args[j], space, &ti, atoms)) { + if (!_slang_typeof_operation_(&args[j], space, &ti, atoms, log)) { slang_typeinfo_destruct(&ti); return NULL; } @@ -737,7 +752,7 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name, } if (funcs->outer_scope != NULL) return _slang_locate_function(funcs->outer_scope, a_name, args, - num_args, space, atoms); + num_args, space, atoms, log); return NULL; } @@ -757,10 +772,10 @@ _slang_typeof_function(slang_atom a_name, const slang_operation * params, GLuint num_params, const slang_name_space * space, slang_type_specifier * spec, GLboolean * exists, - slang_atom_pool * atoms) + slang_atom_pool *atoms, slang_info_log *log) { slang_function *fun = _slang_locate_function(space->funcs, a_name, params, - num_params, space, atoms); + num_params, space, atoms, log); *exists = fun != NULL; if (!fun) return GL_TRUE; /* yes, not false */ diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index 3115b71e08..62cf0009d3 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -27,6 +27,7 @@ #include "imports.h" #include "mtypes.h" +#include "slang_log.h" #include "slang_utility.h" #include "slang_vartable.h" @@ -60,6 +61,7 @@ typedef struct slang_assemble_ctx_ slang_name_space space; struct gl_program *program; slang_var_table *vartable; + slang_info_log *log; struct slang_function_ *CurFunction; struct slang_ir_node_ *CurLoop; } slang_assemble_ctx; @@ -70,7 +72,7 @@ _slang_locate_function(const struct slang_function_scope_ *funcs, slang_atom name, const struct slang_operation_ *params, GLuint num_params, const slang_name_space *space, - slang_atom_pool *); + slang_atom_pool *atoms, slang_info_log *log); extern GLboolean @@ -170,7 +172,8 @@ _slang_typeof_operation(const slang_assemble_ctx *, extern GLboolean _slang_typeof_operation_(const struct slang_operation_ *, const slang_name_space *, - slang_typeinfo *, slang_atom_pool *); + slang_typeinfo *, slang_atom_pool *, + slang_info_log *log); /** * Retrieves type of a function prototype, if one exists. @@ -182,7 +185,7 @@ _slang_typeof_function(slang_atom a_name, const struct slang_operation_ *params, GLuint num_params, const slang_name_space *, slang_type_specifier *spec, GLboolean *exists, - slang_atom_pool *); + slang_atom_pool *, slang_info_log *log); extern GLboolean _slang_type_is_matrix(slang_type_specifier_type); diff --git a/src/mesa/sources b/src/mesa/sources index a7bbc02012..628599c3c5 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -179,10 +179,10 @@ SLANG_SOURCES = \ shader/slang/slang_compile_struct.c \ shader/slang/slang_compile_variable.c \ shader/slang/slang_emit.c \ - shader/slang/slang_error.c \ shader/slang/slang_label.c \ shader/slang/slang_library_noise.c \ shader/slang/slang_link.c \ + shader/slang/slang_log.c \ shader/slang/slang_preprocess.c \ shader/slang/slang_print.c \ shader/slang/slang_simplify.c \ -- cgit v1.2.3 From fd08463dea8fd2e8d805d66488368830dbe53264 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 13 Mar 2007 15:58:40 -0600 Subject: Check for, simplify vec2/3/4(x). Only do call adapting for constructors. --- src/mesa/shader/slang/slang_simplify.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/mesa/shader/slang/slang_simplify.c') diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index 87b117874f..21d004db88 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -263,8 +263,6 @@ _slang_simplify(slang_operation *oper, /* 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]; @@ -277,6 +275,26 @@ _slang_simplify(slang_operation *oper, } } } + + if (oper->num_children == 1 && isFloat[0]) { + /* vec2/3/4(flt, flt) constructor */ + if (oper->type == SLANG_OPER_CALL) { + const char *func = (const char *) oper->a_id; + if (strncmp(func, "vec", 3) == 0 && func[3] >= '2' && func[3] <= '4') { + oper->literal[0] = + oper->literal[1] = + oper->literal[2] = + oper->literal[3] = oper->children[0].literal[0]; + oper->literal_size = func[3] - '0'; + assert(oper->literal_size >= 2); + assert(oper->literal_size <= 4); + slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */ + oper->type = SLANG_OPER_LITERAL_FLOAT; + assert(oper->num_children == 0); + return; + } + } + } } @@ -302,6 +320,10 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, if (dbg) printf("Adapt %d args to %d parameters\n", callOper->num_children, numParams); + /* Only try adapting for constructors */ + if (fun->kind != SLANG_FUNC_CONSTRUCTOR) + return GL_FALSE; + if (callOper->num_children != numParams) { /* number of arguments doesn't match number of parameters */ @@ -406,7 +428,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun, slang_operation *child = slang_operation_new(1); slang_operation_copy(child, &callOper->children[i]); - child->locals->outer_scope = callOper->locals; + child->locals->outer_scope = callOper->children[i].locals; callOper->children[i].type = SLANG_OPER_CALL; callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName); -- cgit v1.2.3