[Mesa-dev] [PATCH 1/5] draw: make sure clipdistances work with geometry shaders

Brian Paul brianp at vmware.com
Tue Jun 11 08:16:20 PDT 2013


On 06/10/2013 08:31 AM, Zack Rusin wrote:
> we were always fetching the info from the vertex shader, but if
> geometry shader is present it should be used as the source of
> that info.
>
> Signed-off-by: Zack Rusin <zackr at vmware.com>
> ---
>   src/gallium/auxiliary/draw/draw_cliptest_tmp.h |    3 ++-
>   src/gallium/auxiliary/draw/draw_context.c      |   11 +++++++++++
>   src/gallium/auxiliary/draw/draw_gs.c           |    6 ++++++
>   src/gallium/auxiliary/draw/draw_gs.h           |    1 +
>   src/gallium/auxiliary/draw/draw_private.h      |    1 +
>   src/gallium/auxiliary/tgsi/tgsi_scan.c         |    2 +-
>   6 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> index 7351559..7a385c8 100644
> --- a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> +++ b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
> @@ -111,7 +111,8 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
>
>            if (flags & DO_CLIP_USER) {
>               unsigned ucp_mask = ucp_enable;
> -            int num_written_clipdistance = pvs->draw->vs.vertex_shader->info.num_written_clipdistance;
> +            int num_written_clipdistance =
> +               draw_current_shader_num_written_clipdistances(pvs->draw);
>               while (ucp_mask) {
>                  unsigned plane_idx = ffs(ucp_mask)-1;
>                  ucp_mask &= ~(1 << plane_idx);
> diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
> index 35063b9..e8480f6 100644
> --- a/src/gallium/auxiliary/draw/draw_context.c
> +++ b/src/gallium/auxiliary/draw/draw_context.c
> @@ -737,9 +737,20 @@ draw_current_shader_clipvertex_output(const struct draw_context *draw)
>   uint
>   draw_current_shader_clipdistance_output(const struct draw_context *draw, int index)
>   {
> +   if (draw->gs.geometry_shader)
> +      return draw->gs.geometry_shader->clipdistance_output[index];
>      return draw->vs.clipdistance_output[index];
>   }
>
> +
> +uint
> +draw_current_shader_num_written_clipdistances(const struct draw_context *draw)
> +{
> +   if (draw->gs.geometry_shader)
> +      return draw->gs.geometry_shader->info.num_written_clipdistance;
> +   return draw->vs.vertex_shader->info.num_written_clipdistance;
> +}
> +
>   /**
>    * Return a pointer/handle for a driver/CSO rasterizer object which
>    * disabled culling, stippling, unfilled tris, etc.
> diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c
> index 67e5117..74c6279 100644
> --- a/src/gallium/auxiliary/draw/draw_gs.c
> +++ b/src/gallium/auxiliary/draw/draw_gs.c
> @@ -791,6 +791,12 @@ draw_create_geometry_shader(struct draw_context *draw,
>            gs->position_output = i;
>         if (gs->info.output_semantic_name[i] == TGSI_SEMANTIC_VIEWPORT_INDEX)
>            gs->viewport_index_output = i;
> +      if (gs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPDIST) {
> +         if (gs->info.output_semantic_index[i] == 0)
> +            gs->clipdistance_output[0] = i;
> +         else
> +            gs->clipdistance_output[1] = i;
> +      }
>      }
>
>      gs->machine = draw->gs.tgsi.machine;
> diff --git a/src/gallium/auxiliary/draw/draw_gs.h b/src/gallium/auxiliary/draw/draw_gs.h
> index 2b08569..543b32d 100644
> --- a/src/gallium/auxiliary/draw/draw_gs.h
> +++ b/src/gallium/auxiliary/draw/draw_gs.h
> @@ -67,6 +67,7 @@ struct draw_geometry_shader {
>      struct tgsi_shader_info info;
>      unsigned position_output;
>      unsigned viewport_index_output;
> +   unsigned clipdistance_output[2];

Why 2?  Are there four clip distances per register, and we need 8 (or 
6?) of them?  Maybe add some comments.


>
>      unsigned max_output_vertices;
>      unsigned primitive_boundary;
> diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
> index f30f9af..fa0b19b 100644
> --- a/src/gallium/auxiliary/draw/draw_private.h
> +++ b/src/gallium/auxiliary/draw/draw_private.h
> @@ -389,6 +389,7 @@ uint draw_current_shader_position_output(const struct draw_context *draw);
>   uint draw_current_shader_viewport_index_output(const struct draw_context *draw);
>   uint draw_current_shader_clipvertex_output(const struct draw_context *draw);
>   uint draw_current_shader_clipdistance_output(const struct draw_context *draw, int index);
> +uint draw_current_shader_num_written_clipdistances(const struct draw_context *draw);
>   int draw_alloc_extra_vertex_attrib(struct draw_context *draw,
>                                      uint semantic_name, uint semantic_index);
>   void draw_remove_extra_vertex_attribs(struct draw_context *draw);
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c
> index d331257..872e4ff 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_scan.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c
> @@ -196,7 +196,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
>                     info->output_semantic_index[reg] = (ubyte)fulldecl->Semantic.Index;
>                     info->num_outputs++;
>
> -                  if (procType == TGSI_PROCESSOR_VERTEX &&
> +                  if ((procType == TGSI_PROCESSOR_VERTEX || procType == TGSI_PROCESSOR_GEOMETRY) &&
>                         fulldecl->Semantic.Name == TGSI_SEMANTIC_CLIPDIST) {
>                        info->num_written_clipdistance += util_bitcount(fulldecl->Declaration.UsageMask);
>                     }
>

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list