[Mesa-dev] [PATCH 3/3] draw/softpipe: add clip vertex support.

Brian Paul brianp at vmware.com
Wed Jan 4 08:37:58 PST 2012


On 01/04/2012 05:13 AM, Dave Airlie wrote:
> From: Dave Airlie<airlied at redhat.com>
>
> softpipe always clipped using the position vector, however for unclipped
> vertices it stored the position in window coordinates, however when position
> and clipping are separated, we need to store the clip-space position and
> the clip-space vertex clip, so we can interpolate both separately.
>
> This means we have to take the clip space position and store it to use later.
>
> This allows softpipe to pass all the clip-vertex piglit tests.
>
> Signed-off-by: Dave Airlie<airlied at redhat.com>
> ---
>   src/gallium/auxiliary/draw/draw_cliptest_tmp.h |   18 ++++++++++++------
>   src/gallium/auxiliary/draw/draw_context.c      |   10 ++++++++++
>   src/gallium/auxiliary/draw/draw_pipe_clip.c    |    9 ++++++---
>   src/gallium/auxiliary/draw/draw_private.h      |    5 +++--
>   src/gallium/auxiliary/draw/draw_pt_fetch.c     |    4 ++--
>   src/gallium/auxiliary/draw/draw_vs.c           |    9 +++++++++
>   src/gallium/auxiliary/draw/draw_vs.h           |    1 +
>   7 files changed, 43 insertions(+), 13 deletions(-)
>
> diff --git a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> index 1ca1529..7ae95a6 100644
> --- a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> +++ b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> @@ -35,11 +35,13 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
>      const float *trans = pvs->draw->viewport.translate;
>      /* const */ float (*plane)[4] = pvs->draw->plane;
>      const unsigned pos = draw_current_shader_position_output(pvs->draw);
> +   const unsigned cv = draw_current_shader_clipvertex_output(pvs->draw);
>      const unsigned ef = pvs->draw->vs.edgeflag_output;
>      const unsigned nr = pvs->draw->nr_planes;
>      const unsigned flags = (FLAGS);
>      unsigned need_pipeline = 0;
>      unsigned j;
> +   unsigned i;
>
>      for (j = 0; j<  info->count; j++) {
>         float *position = out->data[pos];
> @@ -49,10 +51,15 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
>
>         if (flags&  (DO_CLIP_XY | DO_CLIP_XY_GUARD_BAND |
>                      DO_CLIP_FULL_Z | DO_CLIP_HALF_Z | DO_CLIP_USER)) {
> -         out->clip[0] = position[0];
> -         out->clip[1] = position[1];
> -         out->clip[2] = position[2];
> -         out->clip[3] = position[3];
> +         float *clipvertex = position;
> +
> +         if ((flags&  DO_CLIP_USER)&&  cv != pos)
> +            clipvertex = out->data[cv];
> +
> +         for (i = 0; i<  4; i++) {
> +            out->clip[i] = clipvertex[i];
> +            out->pre_clip_pos[i] = position[i];
> +         }
>
>            /* Do the hardwired planes first:
>             */
> @@ -81,9 +88,8 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
>            }
>
>            if (flags&  DO_CLIP_USER) {
> -            unsigned i;
>               for (i = 6; i<  nr; i++) {
> -               if (dot4(position, plane[i])<  0)
> +               if (dot4(clipvertex, plane[i])<  0)
>                     mask |= (1<<i);
>               }
>            }
> diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
> index 9c00687..6b58073 100644
> --- a/src/gallium/auxiliary/draw/draw_context.c
> +++ b/src/gallium/auxiliary/draw/draw_context.c
> @@ -675,6 +675,16 @@ draw_current_shader_position_output(const struct draw_context *draw)
>
>
>   /**
> + * Return the index of the shader output which will contain the
> + * vertex position.
> + */
> +uint
> +draw_current_shader_clipvertex_output(const struct draw_context *draw)
> +{
> +   return draw->vs.clipvertex_output;
> +}
> +
> +/**
>    * Return a pointer/handle for a driver/CSO rasterizer object which
>    * disabled culling, stippling, unfilled tris, etc.
>    * This is used by some pipeline stages (such as wide_point, aa_line
> diff --git a/src/gallium/auxiliary/draw/draw_pipe_clip.c b/src/gallium/auxiliary/draw/draw_pipe_clip.c
> index e1eabe2..fbc8f67 100644
> --- a/src/gallium/auxiliary/draw/draw_pipe_clip.c
> +++ b/src/gallium/auxiliary/draw/draw_pipe_clip.c
> @@ -118,6 +118,7 @@ static void interp( const struct clip_stage *clip,
>   {
>      const unsigned nr_attrs = draw_current_shader_outputs(clip->stage.draw);
>      const unsigned pos_attr = draw_current_shader_position_output(clip->stage.draw);
> +   const unsigned clip_attr = draw_current_shader_clipvertex_output(clip->stage.draw);
>      unsigned j;
>
>      /* Vertex header.
> @@ -130,12 +131,14 @@ static void interp( const struct clip_stage *clip,
>      /* Interpolate the clip-space coords.
>       */
>      interp_attr(dst->clip, t, in->clip, out->clip);
> +   /* interpolate the clip-space position */
> +   interp_attr(dst->pre_clip_pos, t, in->pre_clip_pos, out->pre_clip_pos);
>
>      /* Do the projective divide and viewport transformation to get
>       * new window coordinates:
>       */
>      {
> -      const float *pos = dst->clip;
> +      const float *pos = dst->pre_clip_pos;
>         const float *scale = clip->stage.draw->viewport.scale;
>         const float *trans = clip->stage.draw->viewport.translate;
>         const float oow = 1.0f / pos[3];
> @@ -149,8 +152,8 @@ static void interp( const struct clip_stage *clip,
>      /* Other attributes
>       */
>      for (j = 0; j<  nr_attrs; j++) {
> -      if (j != pos_attr)
> -         interp_attr(dst->data[j], t, in->data[j], out->data[j]);
> +      if (j != pos_attr&&  j != clip_attr)
> +        interp_attr(dst->data[j], t, in->data[j], out->data[j]);
>      }
>   }
>
> diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
> index 89653e1..d101c32 100644
> --- a/src/gallium/auxiliary/draw/draw_private.h
> +++ b/src/gallium/auxiliary/draw/draw_private.h
> @@ -76,7 +76,7 @@ struct vertex_header {
>      unsigned vertex_id:16;
>
>      float clip[4];
> -
> +   float pre_clip_pos[4];

I'd like to keep the blank line between this declaration and the 
following comment.


>      /* This will probably become float (*data)[4] soon:
>       */
>      float data[][4];
> @@ -230,6 +230,7 @@ struct draw_context
>         uint num_vs_outputs;  /**<  convenience, from vertex_shader */
>         uint position_output;
>         uint edgeflag_output;
> +      uint clipvertex_output;
>
>         /** TGSI program interpreter runtime state */
>         struct tgsi_exec_machine *machine;


More information about the mesa-dev mailing list