mesa: Branch 'master' - 2 commits

Brian Paul brianp at kemper.freedesktop.org
Mon Mar 26 19:46:55 UTC 2007


 src/mesa/shader/prog_parameter.c      |    4 ++
 src/mesa/shader/slang/slang_codegen.c |    6 +--
 src/mesa/shader/slang/slang_emit.c    |   65 +++++++++++++---------------------
 3 files changed, 33 insertions(+), 42 deletions(-)

New commits:
diff-tree 768f7231ea354c218d83f5875ae17475640b2a84 (from 680abf8a02bd88e55ebaa81326c7621a745bedd4)
Author: Brian <brian at yutani.localnet.net>
Date:   Mon Mar 26 13:06:33 2007 -0600

    Fix a few issues with computing storage sizes with respect to swizzles.

diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index fa57ef8..4a67d45 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -458,10 +458,10 @@ new_label(slang_label *label)
 }
 
 static slang_ir_node *
-new_float_literal(const float v[4])
+new_float_literal(const float v[4], GLuint size)
 {
-   const GLuint size = (v[0] == v[1] && v[0] == v[2] && v[0] == v[3]) ? 1 : 4;
    slang_ir_node *n = new_node0(IR_FLOAT);
+   assert(size <= 4);
    COPY_4V(n->Value, v);
    /* allocate a storage object, but compute actual location (Index) later */
    n->Store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size);
@@ -2513,7 +2513,7 @@ _slang_gen_operation(slang_assemble_ctx 
    case SLANG_OPER_LITERAL_INT:
       /* fall-through */
    case SLANG_OPER_LITERAL_BOOL:
-      return new_float_literal(oper->literal);
+      return new_float_literal(oper->literal, oper->literal_size);
 
    case SLANG_OPER_POSTINCREMENT:   /* var++ */
       {
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 4bbc7c9..b318402 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -125,7 +125,9 @@ alloc_temp_storage(slang_emit_info *emit
 static void
 free_temp_storage(slang_var_table *vt, slang_ir_node *n)
 {
-   if (n->Store->File == PROGRAM_TEMPORARY && n->Store->Index >= 0) {
+   if (n->Store->File == PROGRAM_TEMPORARY &&
+       n->Store->Index >= 0 &&
+       n->Opcode != IR_SWIZZLE) {
       if (_slang_is_temp(vt, n->Store)) {
          _slang_free_temp(vt, n->Store);
          n->Store->Index = -1;
@@ -142,12 +144,6 @@ static void
 storage_to_dst_reg(struct prog_dst_register *dst, const slang_ir_storage *st,
                    GLuint writemask)
 {
-   static const GLuint defaultWritemask[4] = {
-      WRITEMASK_X,
-      WRITEMASK_X | WRITEMASK_Y,
-      WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z,
-      WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z | WRITEMASK_W
-   };
    assert(st->Index >= 0);
    dst->File = st->File;
    dst->Index = st->Index;
@@ -157,17 +153,10 @@ storage_to_dst_reg(struct prog_dst_regis
    if (st->Size == 1) {
       GLuint comp = GET_SWZ(st->Swizzle, 0);
       assert(comp < 4);
-      assert(writemask & WRITEMASK_X);
-      /*
-      assert((writemask == WRITEMASK_X) ||
-             (writemask == WRITEMASK_Y) ||
-             (writemask == WRITEMASK_Z) ||
-             (writemask == WRITEMASK_W));
-      */
       dst->WriteMask = WRITEMASK_X << comp;
    }
    else {
-      dst->WriteMask = defaultWritemask[st->Size - 1] & writemask;
+      dst->WriteMask = writemask;
    }
 }
 
@@ -195,10 +184,10 @@ storage_to_src_reg(struct prog_src_regis
    else
       src->Swizzle = defaultSwizzle[st->Size - 1]; /*XXX really need this?*/
 
-   assert(GET_SWZ(src->Swizzle, 0) != SWIZZLE_NIL);
-   assert(GET_SWZ(src->Swizzle, 1) != SWIZZLE_NIL);
-   assert(GET_SWZ(src->Swizzle, 2) != SWIZZLE_NIL);
-   assert(GET_SWZ(src->Swizzle, 3) != SWIZZLE_NIL);
+   assert(GET_SWZ(src->Swizzle, 0) <= 3);
+   assert(GET_SWZ(src->Swizzle, 1) <= 3);
+   assert(GET_SWZ(src->Swizzle, 2) <= 3);
+   assert(GET_SWZ(src->Swizzle, 3) <= 3);
 }
 
 
@@ -501,13 +490,9 @@ emit_compare(slang_emit_info *emitInfo, 
    emit(emitInfo, n->Children[0]);
    emit(emitInfo, n->Children[1]);
 
-#if 0
    assert(n->Children[0]->Store->Size == n->Children[1]->Store->Size);
    size = n->Children[0]->Store->Size;
-#else
-   /* XXX kind of a hack for now... */
-   size = MIN2(n->Children[0]->Store->Size, n->Children[1]->Store->Size);
-#endif
+
    if (size == 1) {
       gl_inst_opcode opcode;
 
@@ -1220,7 +1205,10 @@ fix_swizzle(GLuint swizzle)
 }
 
 
-#if 0
+/**
+ * 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)
 {
@@ -1231,7 +1219,6 @@ swizzle_size(GLuint swizzle)
    }
    return size;
 }
-#endif
 
 
 static struct prog_instruction *
@@ -1239,17 +1226,8 @@ emit_swizzle(slang_emit_info *emitInfo, 
 {
    GLuint swizzle;
 
-   /* swizzled storage access */
    (void) emit(emitInfo, n->Children[0]);
 
-   /* "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  = n->Children[0]->Store->Size;
-   /*n->Var = n->Children[0]->Var; XXX for debug */
-   assert(n->Store->Index >= 0);
-
-   swizzle = fix_swizzle(n->Store->Swizzle);
 #ifdef DEBUG
    {
       GLuint s = n->Children[0]->Store->Swizzle;
@@ -1259,16 +1237,24 @@ emit_swizzle(slang_emit_info *emitInfo, 
       assert(GET_SWZ(s, 3) != SWIZZLE_NIL);
    }
 #endif
+   /* For debug: n->Var = n->Children[0]->Var; */
 
-#if 0
+   /* "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);
-   printf("Emit Swizzle reg %d  chSize %d  size %d\n",
+#if 0
+   printf("Emit Swizzle reg %d  chSize %d  size %d  swz %s\n",
           n->Store->Index, n->Children[0]->Store->Size,
-          n->Store->Size);
+          n->Store->Size,
+          _mesa_swizzle_string(n->Store->Swizzle, 0, 0));
 #endif
+
    /* apply this swizzle to child's swizzle to get composed swizzle */
+   swizzle = fix_swizzle(n->Store->Swizzle); /* remove the don't care terms */
    n->Store->Swizzle = swizzle_swizzle(n->Children[0]->Store->Swizzle,
                                        swizzle);
+
    return NULL;
 }
 
@@ -1492,7 +1478,8 @@ emit(slang_emit_info *emitInfo, slang_ir
       return emit_negation(emitInfo, n);
    case IR_FLOAT:
       /* find storage location for this float constant */
-      n->Store->Index = _mesa_add_unnamed_constant(emitInfo->prog->Parameters, n->Value,
+      n->Store->Index = _mesa_add_unnamed_constant(emitInfo->prog->Parameters,
+                                                   n->Value,
                                                    n->Store->Size,
                                                    &n->Store->Swizzle);
       if (n->Store->Index < 0) {
diff-tree 680abf8a02bd88e55ebaa81326c7621a745bedd4 (from 11702680888038a22d9a406ea5646af2902c125e)
Author: Brian <brian at yutani.localnet.net>
Date:   Mon Mar 26 13:04:57 2007 -0600

    In _mesa_lookup_parameter_constant() make sure we return a full, 4-component swizzle.

diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index adffafd..2c8a340 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -532,6 +532,10 @@ _mesa_lookup_parameter_constant(const st
                       }
                    }
                 }
+                /* smear last value to remaining positions */
+                for (; j < 4; j++)
+                   swz[j] = swz[j-1];
+
                 if (match == vSize) {
                    *posOut = i;
                    *swizzleOut = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);



More information about the mesa-commit mailing list