[Mesa-dev] [PATCH V3 1/5] i965 Gen4/5: Compute interpolation status for every varying in one place.

Chris Forbes chrisf at ijw.co.nz
Sun Jul 14 02:39:39 PDT 2013


The program keys are updated accordingly, but the values are not used
yet.

[V1-2]: Signed-off-by: Olivier Galibert <galibert at pobox.com>

V3: Updated for vue_map changes, intel -> brw merge, etc. (Chris Forbes)
Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 src/mesa/drivers/dri/i965/brw_clip.c    | 59 ++++++++++++++++++++++++++++++++-
 src/mesa/drivers/dri/i965/brw_clip.h    |  1 +
 src/mesa/drivers/dri/i965/brw_context.h |  5 +++
 src/mesa/drivers/dri/i965/brw_sf.c      |  7 +++-
 src/mesa/drivers/dri/i965/brw_sf.h      |  1 +
 5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_clip.c b/src/mesa/drivers/dri/i965/brw_clip.c
index 2ebf3f6..488e0a0 100644
--- a/src/mesa/drivers/dri/i965/brw_clip.c
+++ b/src/mesa/drivers/dri/i965/brw_clip.c
@@ -48,6 +48,56 @@
 #define BACK_UNFILLED_BIT   0x2
 
 
+/* Set up interpolation modes for every element in the VUE */
+static void
+brw_setup_vue_interpolation(struct brw_context *brw)
+{
+   const struct gl_fragment_program *fprog = brw->fragment_program;
+   struct brw_vue_map *vue_map = &brw->vue_map_geom_out;
+
+   /* XXX: stuffing this in the context is not really good enough */
+   memset(brw->interpolation_mode, INTERP_QUALIFIER_NONE, BRW_VARYING_SLOT_COUNT);
+
+   if (!fprog)
+      return;
+
+   for (int i=0; i < vue_map->num_slots; i++) {
+      int varying = vue_map->slot_to_varying[i];
+      if (varying == -1)
+         continue;
+
+      /* HPOS always wants noperspective. setting it up here allows
+       * us to not need special handling in the SF program. */
+      if (varying == VARYING_SLOT_POS) {
+         brw->interpolation_mode[i] = INTERP_QUALIFIER_NOPERSPECTIVE;
+         continue;
+      }
+
+      int frag_attrib = varying;
+      if (varying == VARYING_SLOT_BFC0 || varying == VARYING_SLOT_BFC1)
+         frag_attrib = varying - VARYING_SLOT_BFC0 + VARYING_SLOT_COL0;
+
+      if (!(fprog->Base.InputsRead & BITFIELD64_BIT(frag_attrib)))
+         continue;
+
+      enum glsl_interp_qualifier mode = fprog->InterpQualifier[frag_attrib];
+
+      /* If the mode is not specified, the default varies: Color values
+       * follow GL_SHADE_MODEL; everything else is smooth.
+       */
+      if (mode == INTERP_QUALIFIER_NONE) {
+         if (frag_attrib == VARYING_SLOT_COL0 || frag_attrib == VARYING_SLOT_COL1)
+            mode = brw->ctx.Light.ShadeModel == GL_FLAT
+               ? INTERP_QUALIFIER_FLAT : INTERP_QUALIFIER_SMOOTH;
+         else
+            mode = INTERP_QUALIFIER_SMOOTH;
+      }
+
+      brw->interpolation_mode[i] = mode;
+   }
+}
+
+
 static void compile_clip_prog( struct brw_context *brw,
 			     struct brw_clip_prog_key *key )
 {
@@ -141,6 +191,11 @@ brw_upload_clip_prog(struct brw_context *brw)
 
    /* Populate the key:
     */
+
+   /* BRW_NEW_FRAGMENT_PROGRAM, _NEW_LIGHT */
+   brw_setup_vue_interpolation(brw);
+   memcpy(key.interpolation_mode, brw->interpolation_mode, BRW_VARYING_SLOT_COUNT);
+
    /* BRW_NEW_REDUCED_PRIMITIVE */
    key.primitive = brw->reduced_primitive;
    /* BRW_NEW_VUE_MAP_GEOM_OUT */
@@ -256,7 +311,9 @@ const struct brw_tracked_state brw_clip_prog = {
 		_NEW_TRANSFORM |
 		_NEW_POLYGON | 
 		_NEW_BUFFERS),
-      .brw   = (BRW_NEW_REDUCED_PRIMITIVE | BRW_NEW_VUE_MAP_GEOM_OUT)
+      .brw   = (BRW_NEW_FRAGMENT_PROGRAM |
+                BRW_NEW_REDUCED_PRIMITIVE |
+                BRW_NEW_VUE_MAP_GEOM_OUT)
    },
    .emit = brw_upload_clip_prog
 };
diff --git a/src/mesa/drivers/dri/i965/brw_clip.h b/src/mesa/drivers/dri/i965/brw_clip.h
index 02259d4..fcbe2a0 100644
--- a/src/mesa/drivers/dri/i965/brw_clip.h
+++ b/src/mesa/drivers/dri/i965/brw_clip.h
@@ -43,6 +43,7 @@
  */
 struct brw_clip_prog_key {
    GLbitfield64 attrs;
+   unsigned char interpolation_mode[BRW_VARYING_SLOT_COUNT];
    GLuint primitive:4;
    GLuint nr_userclip:4;
    GLuint do_flat_shading:1;
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 86f9f71..a614b96 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1203,6 +1203,11 @@ struct brw_context
    uint32_t render_target_format[MESA_FORMAT_COUNT];
    bool format_supported_as_render_target[MESA_FORMAT_COUNT];
 
+   /* Interpolation modes, one byte per vue slot.
+    * Used Gen4/5 by the clip|sf|wm stages. Ignored on Gen6+.
+    */
+   unsigned char interpolation_mode[BRW_VARYING_SLOT_COUNT];
+
    /* PrimitiveRestart */
    struct {
       bool in_progress;
diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
index d73973c..7cd383c 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -194,6 +194,9 @@ brw_upload_sf_prog(struct brw_context *brw)
    key.do_twoside_color = ((ctx->Light.Enabled && ctx->Light.Model.TwoSide) ||
                            ctx->VertexProgram._TwoSideEnabled);
 
+   /* BRW_NEW_FRAGMENT_PROGRAM | _NEW_LIGHT */
+   memcpy(key.interpolation_mode, brw->interpolation_mode, BRW_VARYING_SLOT_COUNT);
+
    /* _NEW_POLYGON */
    if (key.do_twoside_color) {
       /* If we're rendering to a FBO, we have to invert the polygon
@@ -215,7 +218,9 @@ const struct brw_tracked_state brw_sf_prog = {
    .dirty = {
       .mesa  = (_NEW_HINT | _NEW_LIGHT | _NEW_POLYGON | _NEW_POINT |
                 _NEW_TRANSFORM | _NEW_BUFFERS | _NEW_PROGRAM),
-      .brw   = (BRW_NEW_REDUCED_PRIMITIVE | BRW_NEW_VUE_MAP_GEOM_OUT)
+      .brw   = (BRW_NEW_REDUCED_PRIMITIVE |
+                BRW_NEW_VUE_MAP_GEOM_OUT |
+                BRW_NEW_FRAGMENT_PROGRAM)
    },
    .emit = brw_upload_sf_prog
 };
diff --git a/src/mesa/drivers/dri/i965/brw_sf.h b/src/mesa/drivers/dri/i965/brw_sf.h
index caeb0d0..55a860d 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.h
+++ b/src/mesa/drivers/dri/i965/brw_sf.h
@@ -46,6 +46,7 @@
 
 struct brw_sf_prog_key {
    GLbitfield64 attrs;
+   unsigned char interpolation_mode[BRW_VARYING_SLOT_COUNT];
    uint8_t point_sprite_coord_replace;
    GLuint primitive:2;
    GLuint do_twoside_color:1;
-- 
1.8.3.2



More information about the mesa-dev mailing list