[Mesa-dev] [PATCH 3/8] mesa: Put materials at the end of the generic block.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Wed Jan 31 07:55:57 UTC 2018


From: Mathias Fröhlich <mathias.froehlich at web.de>

The materials are now moved to the end of the
generic attributes block to the range 4-15.

Before, the way the position and generic 0 attribute
is handled was dependent on the presence and kind of
the currently attached vertex program. With this
change the way the position attribute and the generic 0
attribute is treated only depends on the enabled
flag of those two arrays.
This will later help to untangle the update dependencies
between enabled arrays and shader inputs.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/compiler/shader_enums.h   |  7 ++++++-
 src/mesa/tnl/t_context.h      |  4 ++--
 src/mesa/vbo/vbo_exec_array.c | 14 +++++++-------
 src/mesa/vbo/vbo_exec_draw.c  | 10 +++++-----
 src/mesa/vbo/vbo_save_draw.c  |  8 ++++----
 5 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index aa296adb5a..47a017eebc 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -127,6 +127,8 @@ const char *gl_vert_attrib_name(gl_vert_attrib attrib);
  * VERT_ATTRIB_MAT
  *   include the generic shader attributes used to alias
  *   varying material values for the TNL shader programs.
+ *   They are located at the end of the generic attribute
+ *   block not to overlap with the generic 0 attribute.
  */
 #define VERT_ATTRIB_FF(i)           (VERT_ATTRIB_POS + (i))
 #define VERT_ATTRIB_FF_MAX          VERT_ATTRIB_GENERIC0
@@ -137,7 +139,10 @@ const char *gl_vert_attrib_name(gl_vert_attrib attrib);
 #define VERT_ATTRIB_GENERIC(i)      (VERT_ATTRIB_GENERIC0 + (i))
 #define VERT_ATTRIB_GENERIC_MAX     MAX_VERTEX_GENERIC_ATTRIBS
 
-#define VERT_ATTRIB_MAT(i)          VERT_ATTRIB_GENERIC(i)
+#define VERT_ATTRIB_MAT_OFFSET      \
+   (VERT_ATTRIB_GENERIC_MAX - VERT_ATTRIB_MAT_MAX)
+#define VERT_ATTRIB_MAT(i)          \
+   VERT_ATTRIB_GENERIC((i) + VERT_ATTRIB_MAT_OFFSET)
 #define VERT_ATTRIB_MAT_MAX         MAT_ATTRIB_MAX
 
 /**
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index 48d7ced791..082110c607 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -158,8 +158,8 @@ enum {
 #define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0
 #define _TNL_LAST_GENERIC  _TNL_ATTRIB_GENERIC15
 
-#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC0 */
-#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC11 */
+#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC4 */
+#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC15 */
 
 /* Number of available texture attributes */
 #define _TNL_NUM_TEX 8
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 412b6b669c..28f64e1422 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -335,20 +335,20 @@ recalculate_input_bindings(struct gl_context *ctx)
          }
       }
 
-      for (i = 0; i < VERT_ATTRIB_MAT_MAX; i++) {
-         inputs[VERT_ATTRIB_MAT(i)] =
-            &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT + i];
-         const_inputs |= VERT_BIT_MAT(i);
-      }
-
       /* Could use just about anything, just to fill in the empty
        * slots:
        */
-      for (i = VERT_ATTRIB_MAT_MAX; i < VERT_ATTRIB_GENERIC_MAX; i++) {
+      for (i = 0; i < VERT_ATTRIB_MAT_OFFSET; i++) {
          inputs[VERT_ATTRIB_GENERIC(i)] =
             &vbo->currval[VBO_ATTRIB_GENERIC0 + i];
          const_inputs |= VERT_BIT_GENERIC(i);
       }
+
+      for (i = 0; i < VERT_ATTRIB_MAT_MAX; i++) {
+         inputs[VERT_ATTRIB_MAT(i)] =
+            &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT + i];
+         const_inputs |= VERT_BIT_MAT(i);
+      }
       break;
 
    case VP_SHADER:
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index 2b7784694f..b077fbeb6d 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -187,16 +187,16 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
    /* Overlay other active attributes */
    switch (get_vp_mode(exec->ctx)) {
    case VP_FF:
+      for (attr = 0; attr < VERT_ATTRIB_MAT_OFFSET; attr++) {
+         assert(VERT_ATTRIB_GENERIC(attr) < ARRAY_SIZE(exec->vtx.inputs));
+         exec->vtx.inputs[VERT_ATTRIB_GENERIC(attr)] =
+            &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
+      }
       for (attr = 0; attr < VERT_ATTRIB_MAT_MAX; attr++) {
          assert(VERT_ATTRIB_MAT(attr) < ARRAY_SIZE(exec->vtx.inputs));
          exec->vtx.inputs[VERT_ATTRIB_MAT(attr)] =
             &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
       }
-      for (attr = VERT_ATTRIB_MAT_MAX; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
-         assert(VERT_ATTRIB_GENERIC(attr) < ARRAY_SIZE(exec->vtx.inputs));
-         exec->vtx.inputs[VERT_ATTRIB_GENERIC(attr)] =
-            &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
-      }
       map = vbo->map_vp_none;
       break;
    case VP_SHADER:
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index ea149e632d..940739cd29 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -151,14 +151,14 @@ bind_vertex_list(struct gl_context *ctx,
    /* Overlay other active attributes */
    switch (get_vp_mode(ctx)) {
    case VP_FF:
+      for (attr = 0; attr < VERT_ATTRIB_MAT_OFFSET; attr++) {
+         save->inputs[VERT_ATTRIB_GENERIC(attr)] =
+            &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
+      }
       for (attr = 0; attr < VERT_ATTRIB_MAT_MAX; attr++) {
          save->inputs[VERT_ATTRIB_MAT(attr)] =
             &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
       }
-      for (attr = VERT_ATTRIB_MAT_MAX; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
-         save->inputs[VERT_ATTRIB_GENERIC(attr)] =
-            &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
-      }
       map = vbo->map_vp_none;
       break;
    case VP_SHADER:
-- 
2.14.3



More information about the mesa-dev mailing list