[Mesa-dev] [PATCH 2/2] i915: Simplify intel_wpos_* with a helper function.

Eric Anholt eric at anholt.net
Wed Jul 13 12:54:25 PDT 2011


---
 src/mesa/drivers/dri/i915/i915_fragprog.c  |    9 +---
 src/mesa/drivers/dri/i915/intel_tris.c     |   64 ++++++++++-----------------
 src/mesa/drivers/dri/intel/intel_context.h |    1 -
 3 files changed, 27 insertions(+), 47 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c
index ac95d44..6e1d709 100644
--- a/src/mesa/drivers/dri/i915/i915_fragprog.c
+++ b/src/mesa/drivers/dri/i915/i915_fragprog.c
@@ -1342,7 +1342,6 @@ i915ValidateFragmentProgram(struct i915_context *i915)
 
    intel->vertex_attr_count = 0;
    intel->wpos_offset = 0;
-   intel->wpos_size = 0;
    intel->coloroffset = 0;
    intel->specoffset = 0;
 
@@ -1385,17 +1384,15 @@ i915ValidateFragmentProgram(struct i915_context *i915)
          EMIT_ATTR(_TNL_ATTRIB_GENERIC0 + i, EMIT_SZ(sz), 0, sz * 4);
       }
       else if (i == p->wpos_tex) {
-
+	 int wpos_size = 4 * sizeof(float);
          /* If WPOS is required, duplicate the XYZ position data in an
           * unused texture coordinate:
           */
          s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK);
-         s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(4));
+         s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(wpos_size));
 
          intel->wpos_offset = offset;
-         intel->wpos_size = 4 * sizeof(GLuint);
-
-         EMIT_PAD(intel->wpos_size);
+         EMIT_PAD(wpos_size);
       }
    }
 
diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c
index 941c435..a5eab07 100644
--- a/src/mesa/drivers/dri/i915/intel_tris.c
+++ b/src/mesa/drivers/dri/i915/intel_tris.c
@@ -484,28 +484,33 @@ intel_atten_point(struct intel_context *intel, intelVertexPtr v0)
  *                Fixup for I915 WPOS texture coordinate                *
  ***********************************************************************/
 
+static void
+intel_emit_fragcoord(struct intel_context *intel, intelVertexPtr v)
+{
+   struct gl_context *ctx = &intel->ctx;
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   GLuint offset = intel->wpos_offset;
+   float *vertex_position = (float *)v;
+   float *fragcoord = (float *)((char *)v + offset);
+
+   fragcoord[0] = vertex_position[0];
 
+   if (fb->Name)
+      fragcoord[1] = vertex_position[1];
+   else
+      fragcoord[1] = fb->Height - vertex_position[1];
+
+   fragcoord[2] = vertex_position[2];
+   fragcoord[3] = vertex_position[3];
+}
 
 static void
 intel_wpos_triangle(struct intel_context *intel,
                     intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
 {
-   const struct gl_framebuffer *fb = intel->ctx.DrawBuffer;
-   GLuint offset = intel->wpos_offset;
-   GLuint size = intel->wpos_size;
-   GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
-   GLfloat *v1_wpos = (GLfloat *)((char *)v1 + offset);
-   GLfloat *v2_wpos = (GLfloat *)((char *)v2 + offset);
-
-   __memcpy(v0_wpos, v0, size);
-   __memcpy(v1_wpos, v1, size);
-   __memcpy(v2_wpos, v2, size);
-
-   if (!fb->Name) {
-      v0_wpos[1] = -v0_wpos[1] + fb->Height;
-      v1_wpos[1] = -v1_wpos[1] + fb->Height;
-      v2_wpos[1] = -v2_wpos[1] + fb->Height;
-   }
+   intel_emit_fragcoord(intel, v0);
+   intel_emit_fragcoord(intel, v1);
+   intel_emit_fragcoord(intel, v2);
 
    intel_draw_triangle(intel, v0, v1, v2);
 }
@@ -515,20 +520,8 @@ static void
 intel_wpos_line(struct intel_context *intel,
                 intelVertexPtr v0, intelVertexPtr v1)
 {
-   const struct gl_framebuffer *fb = intel->ctx.DrawBuffer;
-   GLuint offset = intel->wpos_offset;
-   GLuint size = intel->wpos_size;
-   GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
-   GLfloat *v1_wpos = (GLfloat *)((char *)v1 + offset);
-
-   __memcpy(v0_wpos, v0, size);
-   __memcpy(v1_wpos, v1, size);
-
-   if (!fb->Name) {
-      v0_wpos[1] = -v0_wpos[1] + fb->Height;
-      v1_wpos[1] = -v1_wpos[1] + fb->Height;
-   }
-
+   intel_emit_fragcoord(intel, v0);
+   intel_emit_fragcoord(intel, v1);
    intel_draw_line(intel, v0, v1);
 }
 
@@ -536,16 +529,7 @@ intel_wpos_line(struct intel_context *intel,
 static void
 intel_wpos_point(struct intel_context *intel, intelVertexPtr v0)
 {
-   const struct gl_framebuffer *fb = intel->ctx.DrawBuffer;
-   GLuint offset = intel->wpos_offset;
-   GLuint size = intel->wpos_size;
-   GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
-
-   __memcpy(v0_wpos, v0, size);
-
-   if (!fb->Name)
-      v0_wpos[1] = -v0_wpos[1] + fb->Height;
-
+   intel_emit_fragcoord(intel, v0);
    intel_draw_point(intel, v0);
 }
 
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index 531382c..b7989dd 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -230,7 +230,6 @@ struct intel_context
    GLuint coloroffset;
    GLuint specoffset;
    GLuint wpos_offset;
-   GLuint wpos_size;
 
    struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
    GLuint vertex_attr_count;
-- 
1.7.5.4



More information about the mesa-dev mailing list