[Mesa-dev] [PATCH] i965: handle gl_PointCoord for Gen4 and Gen5 platforms

Yuanhan Liu yuanhan.liu at linux.intel.com
Tue Feb 28 17:48:28 PST 2012


Ping......

Comments?

Thanks,
Yuanhan Liu

On Mon, Feb 27, 2012 at 03:46:32PM +0800, Yuanhan Liu wrote:
> This patch add the support of gl_PointCoord gl builtin variable for
> platform gen4 and gen5(ILK).
> 
> Unlike gen6+, we don't have a hardware support of gl_PointCoord, means
> hardware will not calculate the interpolation coefficient for you.
> Instead, you should handle it yourself in sf shader stage.
> 
> But badly, gl_PointCoord is a FS instead of VS builtin variable, thus
> it's not included in c.vue_map generated in VS stage. Thus the current
> code doesn't aware of this attribute. And to handle it correctly, we
> need add it to c.vue_map manually to let SF shader generate the needed
> interpolation coefficient for FS shader. SF stage has it's own copy of
> vue_map, thus I think it's safe to do it manually.
> 
> Since handling gl_PointCoord for gen4 and gen5 platforms is somehow a
> little special, I added a lot of comments and hope I didn't overdo it ;)
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45975
> Piglit: glsl-fs-pointcoord and fbo-gl_pointcoord
> 
> NOTE: This is a candidate for stable release branches.
> 
> Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
> ---
>  src/mesa/drivers/dri/i965/brw_context.h |    6 ++++++
>  src/mesa/drivers/dri/i965/brw_fs.cpp    |    9 +++++++++
>  src/mesa/drivers/dri/i965/brw_sf.c      |   26 ++++++++++++++++++++++----
>  src/mesa/drivers/dri/i965/brw_sf.h      |    1 +
>  src/mesa/drivers/dri/i965/brw_sf_emit.c |    4 ++++
>  5 files changed, 42 insertions(+), 4 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
> index 09d8373..7c794ad 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.h
> +++ b/src/mesa/drivers/dri/i965/brw_context.h
> @@ -296,6 +296,12 @@ typedef enum
>     BRW_VERT_RESULT_NDC = VERT_RESULT_MAX,
>     BRW_VERT_RESULT_HPOS_DUPLICATE,
>     BRW_VERT_RESULT_PAD,
> +   /*
> +    * It's actually not a vert_result but just a _mark_ to let sf aware that
> +    * he need do something special to handle gl_PointCoord builtin variable
> +    * correctly. see compile_sf_prog() for more info.
> +    */
> +   BRW_VERT_RESULT_PNTC,
>     BRW_VERT_RESULT_MAX
>  } brw_vert_result;
>  
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index bf59da3..5f3d79d 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -710,6 +710,15 @@ fs_visitor::calculate_urb_setup()
>  	       urb_setup[fp_index] = urb_next++;
>  	 }
>        }
> +
> +      /*
> +       * It's a FS only attribute, and we did interpolation for this attribute
> +       * in SF thread. So, count it here, too.
> +       *
> +       * See compile_sf_prog() for more info.
> +       */
> +      if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(FRAG_ATTRIB_PNTC))
> +         urb_setup[FRAG_ATTRIB_PNTC] = urb_next++;
>     }
>  
>     /* Each attribute is 4 setup channels, each of which is half a reg. */
> diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
> index 6e63583..7950c47 100644
> --- a/src/mesa/drivers/dri/i965/brw_sf.c
> +++ b/src/mesa/drivers/dri/i965/brw_sf.c
> @@ -64,6 +64,16 @@ static void compile_sf_prog( struct brw_context *brw,
>  
>     c.key = *key;
>     c.vue_map = brw->vs.prog_data->vue_map;
> +   if (c.key.do_point_coord) {
> +      /*
> +       * gl_PointCoord is a FS instead of VS builtin variable, thus it's
> +       * not included in c.vue_map generated in VS stage. Here we add
> +       * it manually to let SF shader generate the needed interpolation
> +       * coefficient for FS shader.
> +       */
> +      c.vue_map.vert_result_to_slot[BRW_VERT_RESULT_PNTC] = c.vue_map.num_slots;
> +      c.vue_map.slot_to_vert_result[c.vue_map.num_slots++] = BRW_VERT_RESULT_PNTC;
> +   }
>     c.urb_entry_read_offset = brw_sf_compute_urb_entry_read_offset(intel);
>     c.nr_attr_regs = (c.vue_map.num_slots + 1)/2 - c.urb_entry_read_offset;
>     c.nr_setup_regs = c.nr_attr_regs;
> @@ -125,6 +135,7 @@ brw_upload_sf_prog(struct brw_context *brw)
>  {
>     struct gl_context *ctx = &brw->intel.ctx;
>     struct brw_sf_prog_key key;
> +   bool render_to_fbo = ctx->DrawBuffer->Name != 0;
>  
>     memset(&key, 0, sizeof(key));
>  
> @@ -167,7 +178,15 @@ brw_upload_sf_prog(struct brw_context *brw)
>  	    key.point_sprite_coord_replace |= (1 << i);
>        }
>     }
> -   key.sprite_origin_lower_left = (ctx->Point.SpriteOrigin == GL_LOWER_LEFT);
> +   if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(FRAG_ATTRIB_PNTC))
> +      key.do_point_coord = 1;
> +   /*
> +    * Window coordinates in a FBO are inverted, which means point
> +    * sprite origin must be inverted, too.
> +    */
> +   if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo)
> +      key.sprite_origin_lower_left = true;
> +
>     /* _NEW_LIGHT */
>     key.do_flat_shading = (ctx->Light.ShadeModel == GL_FLAT);
>     key.do_twoside_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
> @@ -176,10 +195,9 @@ brw_upload_sf_prog(struct brw_context *brw)
>     if (key.do_twoside_color) {
>        /* If we're rendering to a FBO, we have to invert the polygon
>         * face orientation, just as we invert the viewport in
> -       * sf_unit_create_from_key().  ctx->DrawBuffer->Name will be
> -       * nonzero if we're rendering to such an FBO.
> +       * sf_unit_create_from_key().
>         */
> -      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW) ^ (ctx->DrawBuffer->Name != 0);
> +      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW) != render_to_fbo;
>     }
>  
>     if (!brw_search_cache(&brw->cache, BRW_SF_PROG,
> diff --git a/src/mesa/drivers/dri/i965/brw_sf.h b/src/mesa/drivers/dri/i965/brw_sf.h
> index 4ef0240..f908fc0 100644
> --- a/src/mesa/drivers/dri/i965/brw_sf.h
> +++ b/src/mesa/drivers/dri/i965/brw_sf.h
> @@ -52,6 +52,7 @@ struct brw_sf_prog_key {
>     GLuint do_flat_shading:1;
>     GLuint frontface_ccw:1;
>     GLuint do_point_sprite:1;
> +   GLuint do_point_coord:1;
>     GLuint sprite_origin_lower_left:1;
>     GLuint userclip_active:1;
>  };
> diff --git a/src/mesa/drivers/dri/i965/brw_sf_emit.c b/src/mesa/drivers/dri/i965/brw_sf_emit.c
> index 1ee0098..ff6383b 100644
> --- a/src/mesa/drivers/dri/i965/brw_sf_emit.c
> +++ b/src/mesa/drivers/dri/i965/brw_sf_emit.c
> @@ -386,6 +386,8 @@ calculate_point_sprite_mask(struct brw_sf_compile *c, GLuint reg)
>        if (c->key.point_sprite_coord_replace & (1 << (vert_result1 - VERT_RESULT_TEX0)))
>  	 pc |= 0x0f;
>     }
> +   if (vert_result1 == BRW_VERT_RESULT_PNTC)
> +      pc |= 0x0f;
>  
>     vert_result2 = vert_reg_to_vert_result(c, reg, 1);
>     if (vert_result2 >= VERT_RESULT_TEX0 && vert_result2 <= VERT_RESULT_TEX7) {
> @@ -393,6 +395,8 @@ calculate_point_sprite_mask(struct brw_sf_compile *c, GLuint reg)
>                                                       VERT_RESULT_TEX0)))
>           pc |= 0xf0;
>     }
> +   if (vert_result2 == BRW_VERT_RESULT_PNTC)
> +      pc |= 0xf0;
>  
>     return pc;
>  }
> -- 
> 1.7.4.4


More information about the mesa-dev mailing list