Previously, this conversion was duplicated in several places in the
i965 driver.  This patch moves it to a common location in mtypes.h,
near the declaration of gl_vert_result and gl_frag_attrib.

I've also added comments to remind us that we may need to revisit the
conversion code when adding elements to gl_vert_result and
gl_frag_attrib.
---
 src/gallium/drivers/i965/brw_wm_glsl.c      |    9 +-----
 src/mesa/drivers/dri/i965/brw_fs.cpp        |   16 +--------
 src/mesa/drivers/dri/i965/brw_vs_constval.c |    8 +---
 src/mesa/drivers/dri/i965/brw_wm_pass2.c    |    9 +-----
 src/mesa/drivers/dri/i965/gen6_sf_state.c   |   15 ++------
 src/mesa/main/mtypes.h                      |   45 +++++++++++++++++++++++++-
 6 files changed, 53 insertions(+), 49 deletions(-)

diff --git a/src/gallium/drivers/i965/brw_wm_glsl.c 
b/src/gallium/drivers/i965/brw_wm_glsl.c
index fb8e40d..9efb003 100644
--- a/src/gallium/drivers/i965/brw_wm_glsl.c
+++ b/src/gallium/drivers/i965/brw_wm_glsl.c
@@ -388,14 +388,7 @@ static void prealloc_reg(struct brw_wm_compile *c)
 
     /* fragment shader inputs */
     for (i = 0; i < VERT_RESULT_MAX; i++) {
-       int fp_input;
-
-       if (i >= VERT_RESULT_VAR0)
-         fp_input = i - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0;
-       else if (i <= VERT_RESULT_TEX7)
-         fp_input = i;
-       else
-         fp_input = -1;
+       int fp_input = vert_result_to_frag_attrib(i);
 
        if (fp_input >= 0 && inputs & (1 << fp_input)) {
          urb_read_length = reg_index;
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8b85f3b..9332373 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -672,14 +672,7 @@ fs_visitor::calculate_urb_setup()
       /* FINISHME: The sf doesn't map VS->FS inputs for us very well. */
       for (unsigned int i = 0; i < VERT_RESULT_MAX; i++) {
         if (c->key.vp_outputs_written & BITFIELD64_BIT(i)) {
-           int fp_index;
-
-           if (i >= VERT_RESULT_VAR0)
-              fp_index = i - (VERT_RESULT_VAR0 - FRAG_ATTRIB_VAR0);
-           else if (i <= VERT_RESULT_TEX7)
-              fp_index = i;
-           else
-              fp_index = -1;
+           int fp_index = vert_result_to_frag_attrib(i);
 
            if (fp_index >= 0)
               urb_setup[fp_index] = urb_next++;
@@ -1828,17 +1821,12 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
    key.vp_outputs_written |= BITFIELD64_BIT(FRAG_ATTRIB_WPOS);
    for (int i = 0; i < FRAG_ATTRIB_MAX; i++) {
-      int vp_index = -1;
-
       if (!(fp->Base.InputsRead & BITFIELD64_BIT(i)))
         continue;
 
       key.proj_attrib_mask |= 1 << i;
 
-      if (i <= FRAG_ATTRIB_TEX7)
-        vp_index = i;
-      else if (i >= FRAG_ATTRIB_VAR0)
-        vp_index = i - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
+      int vp_index = vert_result_to_frag_attrib(i);
 
       if (vp_index >= 0)
         key.vp_outputs_written |= BITFIELD64_BIT(vp_index);
diff --git a/src/mesa/drivers/dri/i965/brw_vs_constval.c 
b/src/mesa/drivers/dri/i965/brw_vs_constval.c
index 47cc0a7..4d9d4b7 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_constval.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_constval.c
@@ -144,14 +144,10 @@ static void calc_sizes( struct tracker *t )
     * which describes the fragment program input sizes.
     */
    for (vertRes = VERT_RESULT_TEX0; vertRes < VERT_RESULT_MAX; vertRes++) {
-      GLint fragAttrib;
 
       /* map vertex program output index to fragment program input index */
-      if (vertRes <= VERT_RESULT_TEX7)
-         fragAttrib = FRAG_ATTRIB_TEX0 + vertRes - VERT_RESULT_TEX0;
-      else if (vertRes >= VERT_RESULT_VAR0)
-         fragAttrib = FRAG_ATTRIB_VAR0 + vertRes - VERT_RESULT_VAR0;
-      else
+      GLint fragAttrib = vert_result_to_frag_attrib(vertRes);
+      if (fragAttrib < 0)
          continue;
       assert(fragAttrib >= FRAG_ATTRIB_TEX0);
       assert(fragAttrib <= FRAG_ATTRIB_MAX);
diff --git a/src/mesa/drivers/dri/i965/brw_wm_pass2.c 
b/src/mesa/drivers/dri/i965/brw_wm_pass2.c
index 8c2b9e7..f1d70f7 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_pass2.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_pass2.c
@@ -94,14 +94,7 @@ static void init_registers( struct brw_wm_compile *c )
    } else {
       for (j = 0; j < VERT_RESULT_MAX; j++) {
         if (c->key.vp_outputs_written & BITFIELD64_BIT(j)) {
-           int fp_index;
-
-           if (j >= VERT_RESULT_VAR0)
-              fp_index = j - (VERT_RESULT_VAR0 - FRAG_ATTRIB_VAR0);
-           else if (j <= VERT_RESULT_TEX7)
-              fp_index = j;
-           else
-              fp_index = -1;
+           int fp_index = vert_result_to_frag_attrib(j);
 
            nr_interp_regs++;
            if (fp_index >= 0)
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c 
b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 5bb731d..714914a 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -35,19 +35,12 @@
 uint32_t
 get_attr_override(struct brw_context *brw, int fs_attr, int two_side_color)
 {
-   int attr_index = 0, i, vs_attr;
+   int attr_index = 0, i;
    int bfc = 0;
+   int vs_attr = frag_attrib_to_vert_result(fs_attr);
 
-   if (fs_attr <= FRAG_ATTRIB_TEX7)
-      vs_attr = fs_attr;
-   else if (fs_attr == FRAG_ATTRIB_FACE)
-      vs_attr = 0; /* XXX */
-   else if (fs_attr == FRAG_ATTRIB_PNTC)
-      vs_attr = 0; /* XXX */
-   else {
-      assert(fs_attr >= FRAG_ATTRIB_VAR0);
-      vs_attr = fs_attr - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
-   }
+   if (vs_attr < 0)
+      vs_attr = 0;
 
    /* Find the source index (0 = first attribute after the 4D position)
     * for this output attribute.  attr is currently a VERT_RESULT_* but should
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 44ebf0a..776872c 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -215,7 +215,9 @@ typedef enum
 
 
 /**
- * Indexes for vertex program result attributes
+ * Indexes for vertex program result attributes.  Note that
+ * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make
+ * assumptions about the layout of this enum.
  */
 typedef enum
 {
@@ -313,7 +315,9 @@ typedef enum
 
 
 /**
- * Indexes for fragment program input attributes.
+ * Indexes for fragment program input attributes.  Note that
+ * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make
+ * assumptions about the layout of this enum.
  */
 typedef enum
 {
@@ -336,6 +340,43 @@ typedef enum
 } gl_frag_attrib;
 
 /**
+ * Convert from a gl_vert_result value to the corresponding gl_frag_attrib.
+ *
+ * VERT_RESULT_HPOS is converted to FRAG_ATTRIB_WPOS.
+ *
+ * gl_vert_result values which have no corresponding gl_frag_attrib
+ * (VERT_RESULT_PSIZ, VERT_RESULT_BFC0, VERT_RESULT_BFC1, and
+ * VERT_RESULT_EDGE) are converted to a value of -1.
+ */
+static inline int vert_result_to_frag_attrib(int vert_result)
+{
+   if (vert_result >= VERT_RESULT_VAR0)
+      return vert_result - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0;
+   else if (vert_result <= VERT_RESULT_TEX7)
+      return vert_result;
+   else
+      return -1;
+}
+
+/**
+ * Convert from a gl_frag_attrib value to the corresponding gl_vert_result.
+ *
+ * FRAG_ATTRIB_WPOS is converted to VERT_RESULT_HPOS.
+ *
+ * gl_frag_attrib values which have no corresponding gl_vert_result
+ * (FRAG_ATTRIB_FACE and FRAG_ATTRIB_PNTC) are converted to a value of -1.
+ */
+static inline int frag_attrib_to_vert_result(int frag_attrib)
+{
+   if (frag_attrib <= FRAG_ATTRIB_TEX7)
+      return frag_attrib;
+   else if (frag_attrib >= FRAG_ATTRIB_VAR0)
+      return frag_attrib - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
+   else
+      return -1;
+}
+
+/**
  * Bitflags for fragment program input attributes.
  */
 /*@{*/
-- 
1.7.6

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to