[Mesa-dev] [PATCH 09/10] mesa: Make NV generic attributes alias the legacy arrays.

Mathias Fröhlich Mathias.Froehlich at gmx.net
Fri Nov 11 09:11:25 PST 2011


The NV_vertex_program generic attributes should alias the legacy
attributes. Simplify aliasing by using the same gl_client_arrays
for legacy and NV_vertex_program attributes.
The same is already done for the current state values.
---
 src/mesa/main/enable.c        |   10 ++--
 src/mesa/main/get.c           |   32 ++++++------
 src/mesa/main/nvprogram.c     |    8 ++--
 src/mesa/main/state.c         |  102 
++++-------------------------------------
 src/mesa/vbo/vbo_exec_array.c |    7 +--
 5 files changed, 37 insertions(+), 122 deletions(-)

diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 6461ac1..7c6a714 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -118,9 +118,9 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean 
state)
          CHECK_EXTENSION(NV_vertex_program, cap);
          {
             GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
-            ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(ctx->Array.ArrayObj-
>VertexAttrib));
-            var = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled;
-            flag = VERT_BIT_GENERIC(n);
+            ASSERT(VERT_ATTRIB_GENERIC_NV(n) < Elements(ctx->Array.ArrayObj-
>VertexAttrib));
+            var = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC_NV(n)].Enabled;
+            flag = VERT_BIT_GENERIC_NV(n);
          }
          break;
 #endif /* FEATURE_NV_vertex_program */
@@ -1312,8 +1312,8 @@ _mesa_IsEnabled( GLenum cap )
          CHECK_EXTENSION(NV_vertex_program);
          {
             GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
-            ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(ctx->Array.ArrayObj-
>VertexAttrib));
-            return (ctx->Array.ArrayObj-
>VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled != 0);
+            ASSERT(VERT_ATTRIB_GENERIC_NV(n) < Elements(ctx->Array.ArrayObj-
>VertexAttrib));
+            return (ctx->Array.ArrayObj-
>VertexAttrib[VERT_ATTRIB_GENERIC_NV(n)].Enabled != 0);
          }
       case GL_MAP1_VERTEX_ATTRIB0_4_NV:
       case GL_MAP1_VERTEX_ATTRIB1_4_NV:
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 551955c..d8851b5 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -998,37 +998,37 @@ static const struct value_desc values[] = {
    /* GL_NV_vertex_program */
    { GL_VERTEX_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY0_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(0)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY0_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(0)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY1_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(1)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY1_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(1)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY2_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(2)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY2_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(2)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY3_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(3)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY3_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(3)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY4_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(4)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY4_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(4)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY5_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(5)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY5_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(5)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY6_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(6)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY6_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(6)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY7_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(7)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY7_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(7)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY8_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(8)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY8_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(8)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY9_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(9)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY9_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(9)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY10_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(10)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY10_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(10)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY11_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(11)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY11_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(11)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY12_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(12)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY12_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(12)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY13_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(13)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY13_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(13)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY14_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(14)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY14_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(14)].Enabled),
      extra_NV_vertex_program },
-   { GL_VERTEX_ATTRIB_ARRAY15_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(15)].Enabled),
+   { GL_VERTEX_ATTRIB_ARRAY15_NV, 
ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC_NV(15)].Enabled),
      extra_NV_vertex_program },
    { GL_MAP1_VERTEX_ATTRIB0_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[0]),
      extra_NV_vertex_program },
diff --git a/src/mesa/main/nvprogram.c b/src/mesa/main/nvprogram.c
index dae1156..23172fb 100644
--- a/src/mesa/main/nvprogram.c
+++ b/src/mesa/main/nvprogram.c
@@ -365,7 +365,7 @@ _mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, 
GLdouble *params)
       return;
    }
 
-   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
+   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC_NV(index)];
 
    switch (pname) {
       case GL_ATTRIB_ARRAY_SIZE_NV:
@@ -409,7 +409,7 @@ _mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, 
GLfloat *params)
       return;
    }
 
-   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
+   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC_NV(index)];
 
    switch (pname) {
       case GL_ATTRIB_ARRAY_SIZE_NV:
@@ -453,7 +453,7 @@ _mesa_GetVertexAttribivNV(GLuint index, GLenum pname, 
GLint *params)
       return;
    }
 
-   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
+   array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC_NV(index)];
 
    switch (pname) {
       case GL_ATTRIB_ARRAY_SIZE_NV:
@@ -508,7 +508,7 @@ _mesa_GetVertexAttribPointervNV(GLuint index, GLenum 
pname, GLvoid **pointer)
       return;
    }
 
-   *pointer = (GLvoid *) ctx->Array.ArrayObj-
>VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
+   *pointer = (GLvoid *) ctx->Array.ArrayObj-
>VertexAttrib[VERT_ATTRIB_GENERIC_NV(index)].Ptr;
 }
 
 void
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index a2b1eca..f4bc697 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -68,6 +68,7 @@ update_separate_specular(struct gl_context *ctx)
 static GLuint
 update_min(GLuint min, struct gl_client_array *array)
 {
+   assert(array->Enabled);
    _mesa_update_array_max_element(array);
    return MIN2(min, array->_MaxElement);
 }
@@ -81,100 +82,17 @@ static void
 update_arrays( struct gl_context *ctx )
 {
    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
-   GLuint i, min = ~0;
+   GLbitfield64 enabled = arrayObj->_Enabled;
+   GLuint min = ~0u;
 
    /* find min of _MaxElement values for all enabled arrays */
-
-   /* 0 */
-   if (ctx->VertexProgram._Current
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]);
-   }
-
-   /* 1 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC1].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC1]);
-   }
-   /* no conventional vertex weight array */
-
-   /* 2 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC2].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC2]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]);
-   }
-
-   /* 3 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC3].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC3]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]);
-   }
-
-   /* 4 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC4].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC4]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1]);
-   }
-
-   /* 5 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC5].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC5]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_FOG]);
-   }
-
-   /* 6 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC6].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC6]);
-   }
-   else if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
-      min = update_min(min, &arrayObj-
>VertexAttrib[VERT_ATTRIB_COLOR_INDEX]);
-   }
-
-   /* 7 */
-   if (ctx->VertexProgram._Enabled
-       && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC7].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC7]);
-   }
-
-   /* 8..15 */
-   for (i = 0; i < VERT_ATTRIB_TEX_MAX; i++) {
-      if (ctx->VertexProgram._Enabled
-          && arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC8 + i].Enabled) {
-         min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC8 + 
i]);
-      }
-      else if (i < ctx->Const.MaxTextureCoordUnits
-               && arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled) {
-         min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)]);
-      }
-   }
-
-   /* 16..31 */
-   if (ctx->VertexProgram._Current) {
-      for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) {
-         if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled) {
-            min = update_min(min, &arrayObj-
>VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
-         }
-      }
-   }
-
-   if (arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
-      min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG]);
+   while (enabled) {
+      GLint attrib = _mesa_ffsll(enabled) - 1;
+      enabled &= ~BITFIELD64_BIT(attrib);
+      if (!ctx->VertexProgram._Current &&
+          VERT_ATTRIB_GENERIC0 <= attrib && attrib <= VERT_ATTRIB_GENERIC15)
+         continue;
+      min = update_min(min, &arrayObj->VertexAttrib[attrib]);
    }
 
    /* _MaxElement is one past the last legal array element */
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 3d8a832..aa7bc3f 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -450,15 +450,12 @@ recalculate_input_bindings(struct gl_context *ctx)
       break;
 
    case VP_NV:
-      /* NV_vertex_program - attribute arrays alias and override
+      /* NV_vertex_program - attribute arrays alias
        * conventional, legacy arrays.  No materials, and the generic
        * slots are vacant.
        */
       for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) {
-	 if (i < VERT_ATTRIB_GENERIC_MAX
-             && exec->array.generic_array[i]->Enabled)
-	    inputs[i] = exec->array.generic_array[i];
-	 else if (exec->array.legacy_array[i]->Enabled)
+	 if (exec->array.legacy_array[i]->Enabled)
 	    inputs[i] = exec->array.legacy_array[i];
 	 else {
 	    inputs[i] = &vbo->legacy_currval[i];
-- 
1.7.4.4



More information about the mesa-dev mailing list