From 929eb00b32dfea9b1ac58923c88d5573872adea1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 11 Dec 2008 18:49:28 -0700 Subject: [PATCH] mesa: glsl clean-ups --- src/mesa/shader/slang/slang_codegen.c | 95 ++++++++++--------- src/mesa/shader/slang/slang_compile.c | 1 + .../shader/slang/slang_compile_operation.c | 1 + .../shader/slang/slang_compile_operation.h | 6 ++ 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 9d6a9d7d1b2..2030cc03faf 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -2490,61 +2490,62 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var) var->declared = GL_TRUE; n = new_node0(IR_VAR_DECL); - if (n) { - _slang_attach_storage(n, var); - assert(var->store); - assert(n->Store == var->store); - assert(n->Store); - assert(n->Store->Index < 0); + if (!n) + return NULL; - if (is_sampler_type(&var->type)) { - n->Store->File = PROGRAM_SAMPLER; - } - else { - n->Store->File = PROGRAM_TEMPORARY; - } + _slang_attach_storage(n, var); + assert(var->store); + assert(n->Store == var->store); + assert(n->Store); + assert(n->Store->Index < 0); + + if (is_sampler_type(&var->type)) { + n->Store->File = PROGRAM_SAMPLER; + } + else { + n->Store->File = PROGRAM_TEMPORARY; + } - n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier); + n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier); - if (n->Store->Size <= 0) { - slang_info_log_error(A->log, "invalid declaration for '%s'", - (char*) var->a_name); - return NULL; - } + if (n->Store->Size <= 0) { + slang_info_log_error(A->log, "invalid declaration for '%s'", + (char*) var->a_name); + return NULL; + } #if 0 - printf("%s var %p %s store=%p index=%d size=%d\n", - __FUNCTION__, (void *) var, (char *) var->a_name, - (void *) n->Store, n->Store->Index, n->Store->Size); + printf("%s var %p %s store=%p index=%d size=%d\n", + __FUNCTION__, (void *) var, (char *) var->a_name, + (void *) n->Store, n->Store->Index, n->Store->Size); #endif - if (var->array_len > 0) { - /* this is an array */ - /* round up the element size to a multiple of 4 */ - GLint sz = (n->Store->Size + 3) & ~3; - /* total size = element size * array length */ - sz *= var->array_len; - n->Store->Size = sz; - } - - assert(n->Store->Size > 0); + if (var->array_len > 0) { + /* this is an array */ + /* round up the element size to a multiple of 4 */ + GLint sz = (n->Store->Size + 3) & ~3; + /* total size = element size * array length */ + sz *= var->array_len; + n->Store->Size = sz; + } - /* setup default swizzle for storing the variable */ - switch (n->Store->Size) { - case 2: - n->Store->Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, - SWIZZLE_NIL, SWIZZLE_NIL); - break; - case 3: - n->Store->Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, - SWIZZLE_Z, SWIZZLE_NIL); - break; - default: - /* Note that float-sized vars may be allocated in any x/y/z/w - * slot, but that won't be determined until code emit time. - */ - n->Store->Swizzle = SWIZZLE_NOOP; - } + /* setup default swizzle for storing the variable */ + /* XXX this may not be needed anymore - remove & test */ + switch (n->Store->Size) { + case 2: + n->Store->Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, + SWIZZLE_NIL, SWIZZLE_NIL); + break; + case 3: + n->Store->Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, + SWIZZLE_Z, SWIZZLE_NIL); + break; + default: + /* Note that float-sized vars may be allocated in any x/y/z/w + * slot, but that won't be determined until code emit time. + */ + n->Store->Swizzle = SWIZZLE_NOOP; } + return n; } diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 68eefd2cf1e..c0f6dc4c93a 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -1477,6 +1477,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, RETURN0; } array_constructor_size = (int) array_size.literal[0]; + op->array_constructor = GL_TRUE; slang_operation_destruct(&array_size); } break; diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c index 53cf6faff97..ecec2d8b7df 100644 --- a/src/mesa/shader/slang/slang_compile_operation.c +++ b/src/mesa/shader/slang/slang_compile_operation.c @@ -44,6 +44,7 @@ slang_operation_construct(slang_operation * oper) oper->num_children = 0; oper->literal[0] = 0.0; oper->literal_size = 1; + oper->array_constructor = GL_FALSE; oper->a_id = SLANG_ATOM_NULL; oper->locals = _slang_variable_scope_new(NULL); if (oper->locals == NULL) diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h index ec99338cb88..37af5d617c9 100644 --- a/src/mesa/shader/slang/slang_compile_operation.h +++ b/src/mesa/shader/slang/slang_compile_operation.h @@ -121,6 +121,12 @@ typedef struct slang_operation_ struct slang_function_ *fun; /**< If type == SLANG_OPER_CALL */ struct slang_variable_ *var; /**< If type == slang_oper_identier */ struct slang_label_ *label; /**< If type == SLANG_OPER_LABEL */ + /** If type==SLANG_OPER_CALL and we're calling an array constructor, + * for which there's no real function, we need to have a flag to + * indicate such. num_children indicates number of elements. + */ + GLboolean array_constructor; + double x; } slang_operation; -- 2.30.2