From 7f3d6e74817e8880a0712c85f2b41fd88cf6a347 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 22 Jul 2008 18:27:56 -0600 Subject: [PATCH] mesa: glsl: rework swizzle storage handling Build on the heirarchal approach implemented for arrays/structs. --- src/mesa/shader/slang/slang_builtin.c | 12 +++--- src/mesa/shader/slang/slang_codegen.c | 24 ++++++++++- src/mesa/shader/slang/slang_emit.c | 57 ++++++--------------------- 3 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/mesa/shader/slang/slang_builtin.c b/src/mesa/shader/slang/slang_builtin.c index f99a59e3e1b..ed6de40d4b6 100644 --- a/src/mesa/shader/slang/slang_builtin.c +++ b/src/mesa/shader/slang/slang_builtin.c @@ -439,13 +439,11 @@ _slang_alloc_statevar(slang_ir_node *n, pos = lookup_statevar(var, index1, index2, field, &swizzle, paramList); assert(pos >= 0); if (pos >= 0) { - /* XXX should overwrite Store's fields instead of changing pointers - * since there may be a child storage_info pointing to this one. - */ - n0->Store = _slang_new_ir_storage_swz(PROGRAM_STATE_VAR, - pos, - n0->Store->Size, - swizzle); + /* newly resolved storage for the statevar/constant/uniform */ + n0->Store->File = PROGRAM_STATE_VAR; + n0->Store->Index = pos; + n0->Store->Swizzle = swizzle; + n0->Store->Parent = NULL; } return pos; } diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 6e5a54773ed..d4bf99f78f9 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -2630,14 +2630,34 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) } + +/** + * Return the number of components actually named by the swizzle. + * Recall that swizzles may have undefined/don't-care values. + */ +static GLuint +swizzle_size(GLuint swizzle) +{ + GLuint size = 0, i; + for (i = 0; i < 4; i++) { + GLuint swz = GET_SWZ(swizzle, i); + size += (swz >= 0 && swz <= 3); + } + return size; +} + + static slang_ir_node * _slang_gen_swizzle(slang_ir_node *child, GLuint swizzle) { - /* XXX should rewrite this to use relative/Parent storage */ slang_ir_node *n = new_node1(IR_SWIZZLE, child); assert(child); if (n) { - n->Store = _slang_new_ir_storage_swz(PROGRAM_UNDEFINED, -1, -1, swizzle); + assert(!n->Store); + n->Store = _slang_new_ir_storage_relative(0, + swizzle_size(swizzle), + child->Store); + n->Store->Swizzle = swizzle; } return n; } diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index dc02b2f491f..912c325bb2f 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -1505,57 +1505,18 @@ emit_cont_break_if_true(slang_emit_info *emitInfo, slang_ir_node *n) } -/** - * Return the number of components actually named by the swizzle. - * Recall that swizzles may have undefined/don't-care values. - */ -static GLuint -swizzle_size(GLuint swizzle) -{ - GLuint size = 0, i; - for (i = 0; i < 4; i++) { - GLuint swz = GET_SWZ(swizzle, i); - size += (swz >= 0 && swz <= 3); - } - return size; -} - - static struct prog_instruction * emit_swizzle(slang_emit_info *emitInfo, slang_ir_node *n) { - GLuint swizzle; struct prog_instruction *inst; inst = emit(emitInfo, n->Children[0]); - /* For debug: n->Var = n->Children[0]->Var; */ + /* setup storage info, if needed */ + if (!n->Store->Parent) + n->Store->Parent = n->Children[0]->Store; - /* "pull-up" the child's storage info, applying our swizzle info */ - n->Store->File = n->Children[0]->Store->File; - n->Store->Index = n->Children[0]->Store->Index; - n->Store->Size = swizzle_size(n->Store->Swizzle); -#if 0 - printf("Emit Swizzle %s reg %d chSize %d mySize %d\n", - _mesa_swizzle_string(n->Store->Swizzle, 0, 0), - n->Store->Index, n->Children[0]->Store->Size, - n->Store->Size); -#endif - - /* apply this swizzle to child's swizzle to get composed swizzle */ - swizzle = fix_swizzle(n->Store->Swizzle); /* remove the don't care terms */ - -#ifdef DEBUG - { - assert(GET_SWZ(swizzle, 0) != SWIZZLE_NIL); - assert(GET_SWZ(swizzle, 1) != SWIZZLE_NIL); - assert(GET_SWZ(swizzle, 2) != SWIZZLE_NIL); - assert(GET_SWZ(swizzle, 3) != SWIZZLE_NIL); - } -#endif - - n->Store->Swizzle = _slang_swizzle_swizzle(n->Children[0]->Store->Swizzle, - swizzle); + assert(n->Store->Parent); return inst; } @@ -1614,7 +1575,11 @@ emit_array_element(slang_emit_info *emitInfo, slang_ir_node *n) /* resolve new absolute storage location */ assert(n->Store); n->Store->File = root->File; - n->Store->Index = index; + if (root->File == PROGRAM_STATE_VAR) + n->Store->Index = 0; + else + n->Store->Index = index; + n->Store->Parent = NULL; } else { @@ -1639,6 +1604,10 @@ emit_array_element(slang_emit_info *emitInfo, slang_ir_node *n) n->Store->RelAddr = GL_TRUE; } + /* if array element size is one, make sure we only access X */ + if (n->Store->Size == 1) + n->Store->Swizzle = SWIZZLE_XXXX; + return NULL; /* no instruction */ } -- 2.30.2