diff options
author | Brian Paul <[email protected]> | 2008-07-22 18:27:56 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2008-07-29 17:20:30 -0600 |
commit | 01c0558f70ead32db9b7da4ebdc2b33d2477c3e5 (patch) | |
tree | d67ffa053c72d965bdc41187ba086982112d71a8 | |
parent | fb3422a241d7483c108f05290f966ffdbd219c3f (diff) |
mesa: glsl: rework swizzle storage handling
Build on the heirarchal approach implemented for arrays/structs.
-rw-r--r-- | src/mesa/shader/slang/slang_builtin.c | 12 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 24 | ||||
-rw-r--r-- | 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 803501e1541..a98232e3085 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -2608,14 +2608,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 */ } |