From 47331842d4956fb7ccff002d9b86097749345d99 Mon Sep 17 00:00:00 2001 From: Brian Paul <brian.paul@tungstengraphics.com> Date: Fri, 12 Dec 2008 13:05:29 -0700 Subject: mesa: fix some more GLSL 1.20 array things. Function that return arrays should work now. (cherry picked from commit 8571401d7d7c9c91c6f053e5dc8c94a4567140fe) --- src/mesa/shader/slang/slang_codegen.c | 14 +++++++++++--- src/mesa/shader/slang/slang_compile.c | 31 ++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 12 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 04ed8496e64..b7e39e60276 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -67,9 +67,9 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper); * Returns GL_FALSE otherwise. */ static GLboolean -typeof_operation(const struct slang_assemble_ctx_ * A, - slang_operation * op, - slang_typeinfo * ti) +typeof_operation(const struct slang_assemble_ctx_ *A, + slang_operation *op, + slang_typeinfo *ti) { return _slang_typeof_operation(op, &A->space, ti, A->atoms, A->log); } @@ -2556,6 +2556,14 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var, (void *) store, store->Index, store->Size); #endif + if (var->type.array_len > 0) { + /* the type is an array, ex: float[4] x; */ + GLint sz = (store->Size + 3) & ~3; + /* total size = element size * array length */ + sz *= var->type.array_len; + store->Size = sz; + } + if (var->array_len > 0) { /* this is an array */ /* round up the element size to a multiple of 4 */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index aef874b70ba..6803e5a13c5 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -345,6 +345,20 @@ calculate_var_size(slang_parse_ctx * C, slang_output_ctx * O, return GL_TRUE; } +static void +promote_type_to_array(slang_parse_ctx *C, + slang_fully_specified_type *type, + GLint array_len) +{ + slang_type_specifier *baseType = + slang_type_specifier_new(type->specifier.type, NULL, NULL); + + type->specifier.type = SLANG_SPEC_ARRAY; + type->specifier._array = baseType; + type->array_len = array_len; +} + + static GLboolean convert_to_array(slang_parse_ctx * C, slang_variable * var, const slang_type_specifier * sp) @@ -889,6 +903,11 @@ parse_fully_specified_type(slang_parse_ctx * C, slang_output_ctx * O, RETURN0; } + if (type->array_len >= 0) { + /* convert type to array type (ex: convert "int" to "array of int" */ + promote_type_to_array(C, type, type->array_len); + } + return 1; } @@ -1972,6 +1991,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, var->type.centroid = type->centroid; var->type.precision = type->precision; var->type.variant = type->variant; + var->type.array_len = type->array_len; var->a_name = a_name; if (var->a_name == SLANG_ATOM_NULL) RETURN0; @@ -1979,15 +1999,8 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, switch (*C->I++) { case VARIABLE_NONE: /* simple variable declarator - just copy the specifier */ - if (type->array_len >= 0) { - /* The type was something like "float[4]" */ - convert_to_array(C, var, &type->specifier); - var->array_len = type->array_len; - } - else { - if (!slang_type_specifier_copy(&var->type.specifier, &type->specifier)) - RETURN0; - } + if (!slang_type_specifier_copy(&var->type.specifier, &type->specifier)) + RETURN0; break; case VARIABLE_INITIALIZER: /* initialized variable - copy the specifier and parse the expression */ -- cgit v1.2.3