diff options
author | Brian Paul <[email protected]> | 2008-12-12 09:56:13 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2008-12-12 09:56:13 -0700 |
commit | ade777ea1b62e2280c9f05fa09927a8f9bb63f4f (patch) | |
tree | 8747530242f2b92d4d44dab1a3ad595a7132671f | |
parent | 1737f2dbdd8d9d6b1da140340323cbf83f7bd592 (diff) |
mesa: checkpoint: GLSL 1.20 array constructors
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 50 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_function.c | 20 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_function.h | 3 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_storage.h | 1 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_typeinfo.c | 28 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_typeinfo.h | 10 |
7 files changed, 92 insertions, 24 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 7e32c1ac2fe..d50319432e7 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1757,18 +1757,12 @@ _slang_find_function_by_max_argc(slang_function_scope *scope, * struct type. */ static slang_function * -_slang_make_constructor(slang_assemble_ctx *A, slang_struct *str) +_slang_make_struct_constructor(slang_assemble_ctx *A, slang_struct *str) { const GLint numFields = str->fields->num_variables; - - slang_function *fun = (slang_function *) _mesa_malloc(sizeof(slang_function)); - if (!fun) - return NULL; - - slang_function_construct(fun); + slang_function *fun = slang_new_function(SLANG_FUNC_CONSTRUCTOR); /* function header (name, return type) */ - fun->kind = SLANG_FUNC_CONSTRUCTOR; fun->header.a_name = str->a_name; fun->header.type.qualifier = SLANG_QUAL_NONE; fun->header.type.specifier.type = SLANG_SPEC_STRUCT; @@ -1887,7 +1881,6 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str) ret->children[0].type = SLANG_OPER_IDENTIFIER; ret->children[0].a_id = var->a_name; ret->children[0].locals = _slang_variable_scope_new(scope); - } } /* @@ -1910,7 +1903,7 @@ _slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name) /* found a structure type that matches the function name */ if (!str->constructor) { /* create the constructor function now */ - str->constructor = _slang_make_constructor(A, str); + str->constructor = _slang_make_struct_constructor(A, str); } return str->constructor; } @@ -1919,6 +1912,29 @@ _slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name) } +/** + * Generate a new slang_function to satisfy a call to an array constructor. + * Ex: float[3](1., 2., 3.) + */ +static slang_function * +_slang_make_array_constructor(slang_assemble_ctx *A, slang_operation *oper) +{ + slang_function *fun = slang_new_function(SLANG_FUNC_CONSTRUCTOR); + if (fun) { + slang_type_specifier_type baseType = + slang_type_specifier_type_from_string((char *) oper->a_id); + + fun->header.a_name = oper->a_id; + fun->header.type.qualifier = SLANG_QUAL_NONE; + fun->header.type.specifier.type = SLANG_SPEC_ARRAY; + fun->header.type.specifier._array = + slang_type_specifier_new(baseType, NULL, NULL); + + + } + return fun; +} + static GLboolean _slang_is_vec_mat_type(const char *name) @@ -1959,11 +1975,15 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, if (atom == SLANG_ATOM_NULL) return NULL; - /* - * First, try to find function by name and exact argument type matching. - */ - fun = _slang_locate_function(A->space.funcs, atom, params, param_count, - &A->space, A->atoms, A->log, &error); + if (oper->array_constructor) { + /* this needs special handling */ + fun = _slang_make_array_constructor(A, oper); + } + else { + /* Try to find function by name and exact argument type matching */ + fun = _slang_locate_function(A->space.funcs, atom, params, param_count, + &A->space, A->atoms, A->log, &error); + } if (error) { slang_info_log_error(A->log, diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index c0f6dc4c93a..ebc98c6c08e 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -2181,8 +2181,8 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, /* destroy the existing function declaration and replace it * with the new one, remember to save the fixup table */ - parsed_func.fixups = found_func->fixups; - slang_fixup_table_init(&found_func->fixups); + //parsed_func.fixups = found_func->fixups; + //slang_fixup_table_init(&found_func->fixups); slang_function_destruct(found_func); *found_func = parsed_func; } diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c index 8405d7f778c..bc926e6c0e8 100644 --- a/src/mesa/shader/slang/slang_compile_function.c +++ b/src/mesa/shader/slang/slang_compile_function.c @@ -86,8 +86,8 @@ slang_function_construct(slang_function * func) _slang_variable_scope_ctr(func->parameters); func->param_count = 0; func->body = NULL; - func->address = ~0; - slang_fixup_table_init(&func->fixups); + //func->address = ~0; + //slang_fixup_table_init(&func->fixups); return 1; } @@ -101,9 +101,23 @@ slang_function_destruct(slang_function * func) slang_operation_destruct(func->body); _slang_free(func->body); } - slang_fixup_table_free(&func->fixups); + //slang_fixup_table_free(&func->fixups); } + +slang_function * +slang_new_function(slang_function_kind kind) +{ + slang_function *fun = (slang_function *) + _mesa_malloc(sizeof(slang_function)); + if (fun) { + slang_function_construct(fun); + fun->kind = kind; + } + return fun; +} + + /* * slang_function_scope */ diff --git a/src/mesa/shader/slang/slang_compile_function.h b/src/mesa/shader/slang/slang_compile_function.h index a59b094e08d..7fd697ddc84 100644 --- a/src/mesa/shader/slang/slang_compile_function.h +++ b/src/mesa/shader/slang/slang_compile_function.h @@ -64,12 +64,15 @@ typedef struct slang_function_ slang_variable_scope *parameters; /**< formal parameters AND local vars */ unsigned int param_count; /**< number of formal params (no locals) */ slang_operation *body; /**< The instruction tree */ +#if 0 unsigned int address; /**< Address of this func in memory */ slang_fixup_table fixups; /**< Mem locations which need func's address */ +#endif } slang_function; extern int slang_function_construct(slang_function *); extern void slang_function_destruct(slang_function *); +extern slang_function *slang_new_function(slang_function_kind kind); /** diff --git a/src/mesa/shader/slang/slang_storage.h b/src/mesa/shader/slang/slang_storage.h index d3047ee5164..1876a36dd63 100644 --- a/src/mesa/shader/slang/slang_storage.h +++ b/src/mesa/shader/slang/slang_storage.h @@ -26,7 +26,6 @@ #define SLANG_STORAGE_H #include "slang_compile.h" -#include "slang_typeinfo.h" /* diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index b1afd969d95..7fa357ca14d 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -187,6 +187,21 @@ slang_type_specifier_dtr(slang_type_specifier * self) } } +slang_type_specifier * +slang_type_specifier_new(slang_type_specifier_type type, + struct slang_struct_ *_struct, + struct slang_type_specifier_ *_array) +{ + slang_type_specifier *spec = + (slang_type_specifier *) _mesa_malloc(sizeof(slang_type_specifier)); + if (spec) { + spec->type = type; + spec->_struct = _struct; + spec->_array = _array; + } + return spec; +} + GLboolean slang_type_specifier_copy(slang_type_specifier * x, const slang_type_specifier * y) @@ -583,7 +598,18 @@ _slang_typeof_operation_(slang_operation * op, } break; case SLANG_OPER_CALL: - if (op->fun) { + if (op->array_constructor) { + /* build array typeinfo */ + ti->spec.type = SLANG_SPEC_ARRAY; + ti->spec._array = (slang_type_specifier *) + _slang_alloc(sizeof(slang_type_specifier)); + slang_type_specifier_ctr(ti->spec._array); + + ti->spec._array->type = + slang_type_specifier_type_from_string((char *) op->a_id); + ti->array_len = op->num_children; + } + else if (op->fun) { /* we've resolved this call before */ slang_type_specifier_copy(&ti->spec, &op->fun->header.type.specifier); } diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index b3ad06b65c2..cde468bc4e2 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -134,8 +134,8 @@ typedef enum slang_type_specifier_type_ typedef struct slang_type_specifier_ { slang_type_specifier_type type; - struct slang_struct_ *_struct; /**< used if type == spec_struct */ - struct slang_type_specifier_ *_array; /**< used if type == spec_array */ + struct slang_struct_ *_struct; /**< if type == SLANG_SPEC_STRUCT */ + struct slang_type_specifier_ *_array; /**< if type == SLANG_SPEC_ARRAY */ } slang_type_specifier; @@ -145,6 +145,12 @@ slang_type_specifier_ctr(slang_type_specifier *); extern GLvoid slang_type_specifier_dtr(slang_type_specifier *); +extern slang_type_specifier * +slang_type_specifier_new(slang_type_specifier_type type, + struct slang_struct_ *_struct, + struct slang_type_specifier_ *_array); + + extern GLboolean slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *); |