[Mesa-dev] [PATCH 10/24] st/mesa: optimize sampler state translation code

Timothy Arceri tarceri at itsqueeze.com
Tue Jun 13 06:18:09 UTC 2017


Should we add some asserts here to catch invalid values passed to these 
functions?

Either way:

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

On 13/06/17 04:18, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
> 
> ---
>   src/mesa/state_tracker/st_atom_sampler.c | 79 +++++++++++++-------------------
>   1 file changed, 31 insertions(+), 48 deletions(-)
> 
> diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
> index 9695069..ea231f3 100644
> --- a/src/mesa/state_tracker/st_atom_sampler.c
> +++ b/src/mesa/state_tracker/st_atom_sampler.c
> @@ -51,85 +51,68 @@
>   
>   #include "util/u_format.h"
>   
>   
>   /**
>    * Convert GLenum texcoord wrap tokens to pipe tokens.
>    */
>   static GLuint
>   gl_wrap_xlate(GLenum wrap)
>   {
> -   switch (wrap) {
> -   case GL_REPEAT:
> -      return PIPE_TEX_WRAP_REPEAT;
> -   case GL_CLAMP:
> -      return PIPE_TEX_WRAP_CLAMP;
> -   case GL_CLAMP_TO_EDGE:
> -      return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
> -   case GL_CLAMP_TO_BORDER:
> -      return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
> -   case GL_MIRRORED_REPEAT:
> -      return PIPE_TEX_WRAP_MIRROR_REPEAT;
> -   case GL_MIRROR_CLAMP_EXT:
> -      return PIPE_TEX_WRAP_MIRROR_CLAMP;
> -   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
> -      return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
> -   case GL_MIRROR_CLAMP_TO_BORDER_EXT:
> -      return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
> -   default:
> -      assert(0);
> -      return 0;
> -   }
> +   /* Take advantage of how the enums are defined. */
> +   static const unsigned table[32] = {
> +      PIPE_TEX_WRAP_CLAMP,
> +      PIPE_TEX_WRAP_REPEAT,
> +      PIPE_TEX_WRAP_MIRROR_CLAMP,
> +      PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE,
> +      0,
> +      0,
> +      0,
> +      0,
> +      0,
> +      0,
> +      0,
> +      0,
> +      0,
> +      PIPE_TEX_WRAP_CLAMP_TO_BORDER,
> +      0,
> +      PIPE_TEX_WRAP_CLAMP_TO_EDGE,
> +      PIPE_TEX_WRAP_MIRROR_REPEAT,
> +      0,
> +      PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER,
> +   };
> +
> +   return table[wrap & 0x1f];
>   }
>   
>   
>   static GLuint
>   gl_filter_to_mip_filter(GLenum filter)
>   {
> -   switch (filter) {
> -   case GL_NEAREST:
> -   case GL_LINEAR:
> +   /* Take advantage of how the enums are defined. */
> +   if (filter <= GL_LINEAR)
>         return PIPE_TEX_MIPFILTER_NONE;
> -
> -   case GL_NEAREST_MIPMAP_NEAREST:
> -   case GL_LINEAR_MIPMAP_NEAREST:
> +   if (filter <= GL_LINEAR_MIPMAP_NEAREST)
>         return PIPE_TEX_MIPFILTER_NEAREST;
>   
> -   case GL_NEAREST_MIPMAP_LINEAR:
> -   case GL_LINEAR_MIPMAP_LINEAR:
> -      return PIPE_TEX_MIPFILTER_LINEAR;
> -
> -   default:
> -      assert(0);
> -      return PIPE_TEX_MIPFILTER_NONE;
> -   }
> +   return PIPE_TEX_MIPFILTER_LINEAR;
>   }
>   
>   
>   static GLuint
>   gl_filter_to_img_filter(GLenum filter)
>   {
> -   switch (filter) {
> -   case GL_NEAREST:
> -   case GL_NEAREST_MIPMAP_NEAREST:
> -   case GL_NEAREST_MIPMAP_LINEAR:
> -      return PIPE_TEX_FILTER_NEAREST;
> -
> -   case GL_LINEAR:
> -   case GL_LINEAR_MIPMAP_NEAREST:
> -   case GL_LINEAR_MIPMAP_LINEAR:
> +   /* Take advantage of how the enums are defined. */
> +   if (filter & 1)
>         return PIPE_TEX_FILTER_LINEAR;
>   
> -   default:
> -      assert(0);
> -      return PIPE_TEX_FILTER_NEAREST;
> -   }
> +   return PIPE_TEX_FILTER_NEAREST;
>   }
>   
>   
>   /**
>    * Convert a gl_sampler_object to a pipe_sampler_state object.
>    */
>   void
>   st_convert_sampler(const struct st_context *st,
>                      const struct gl_texture_object *texobj,
>                      const struct gl_sampler_object *msamp,
> 


More information about the mesa-dev mailing list