[Mesa-dev] [PATCH 7/7] st/mesa: use one big translation table in st_pipe_vertex_format

Ilia Mirkin imirkin at alum.mit.edu
Fri Apr 14 15:51:31 UTC 2017


Patches 2-7 are

Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>

On Fri, Apr 14, 2017 at 11:07 AM, Marek Olšák <maraeo at gmail.com> wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> for lower overhead.
> ---
>  src/mesa/state_tracker/st_atom_array.c | 469 ++++++++++++++++-----------------
>  1 file changed, 227 insertions(+), 242 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
> index 221b2c7..6cfbd24 100644
> --- a/src/mesa/state_tracker/st_atom_array.c
> +++ b/src/mesa/state_tracker/st_atom_array.c
> @@ -40,284 +40,269 @@
>  #include "st_atom.h"
>  #include "st_cb_bufferobjects.h"
>  #include "st_draw.h"
>  #include "st_program.h"
>
>  #include "cso_cache/cso_context.h"
>  #include "util/u_math.h"
>  #include "main/bufferobj.h"
>  #include "main/glformats.h"
>
> -
> -static GLuint double_types[4] = {
> -   PIPE_FORMAT_R64_FLOAT,
> -   PIPE_FORMAT_R64G64_FLOAT,
> -   PIPE_FORMAT_R64G64B64_FLOAT,
> -   PIPE_FORMAT_R64G64B64A64_FLOAT
> -};
> -
> -static GLuint float_types[4] = {
> -   PIPE_FORMAT_R32_FLOAT,
> -   PIPE_FORMAT_R32G32_FLOAT,
> -   PIPE_FORMAT_R32G32B32_FLOAT,
> -   PIPE_FORMAT_R32G32B32A32_FLOAT
> -};
> -
> -static GLuint half_float_types[4] = {
> -   PIPE_FORMAT_R16_FLOAT,
> -   PIPE_FORMAT_R16G16_FLOAT,
> -   PIPE_FORMAT_R16G16B16_FLOAT,
> -   PIPE_FORMAT_R16G16B16A16_FLOAT
> -};
> -
> -static GLuint uint_types_norm[4] = {
> -   PIPE_FORMAT_R32_UNORM,
> -   PIPE_FORMAT_R32G32_UNORM,
> -   PIPE_FORMAT_R32G32B32_UNORM,
> -   PIPE_FORMAT_R32G32B32A32_UNORM
> -};
> -
> -static GLuint uint_types_scale[4] = {
> -   PIPE_FORMAT_R32_USCALED,
> -   PIPE_FORMAT_R32G32_USCALED,
> -   PIPE_FORMAT_R32G32B32_USCALED,
> -   PIPE_FORMAT_R32G32B32A32_USCALED
> -};
> -
> -static GLuint uint_types_int[4] = {
> -   PIPE_FORMAT_R32_UINT,
> -   PIPE_FORMAT_R32G32_UINT,
> -   PIPE_FORMAT_R32G32B32_UINT,
> -   PIPE_FORMAT_R32G32B32A32_UINT
> -};
> -
> -static GLuint int_types_norm[4] = {
> -   PIPE_FORMAT_R32_SNORM,
> -   PIPE_FORMAT_R32G32_SNORM,
> -   PIPE_FORMAT_R32G32B32_SNORM,
> -   PIPE_FORMAT_R32G32B32A32_SNORM
> -};
> -
> -static GLuint int_types_scale[4] = {
> -   PIPE_FORMAT_R32_SSCALED,
> -   PIPE_FORMAT_R32G32_SSCALED,
> -   PIPE_FORMAT_R32G32B32_SSCALED,
> -   PIPE_FORMAT_R32G32B32A32_SSCALED
> -};
> -
> -static GLuint int_types_int[4] = {
> -   PIPE_FORMAT_R32_SINT,
> -   PIPE_FORMAT_R32G32_SINT,
> -   PIPE_FORMAT_R32G32B32_SINT,
> -   PIPE_FORMAT_R32G32B32A32_SINT
> -};
> -
> -static GLuint ushort_types_norm[4] = {
> -   PIPE_FORMAT_R16_UNORM,
> -   PIPE_FORMAT_R16G16_UNORM,
> -   PIPE_FORMAT_R16G16B16_UNORM,
> -   PIPE_FORMAT_R16G16B16A16_UNORM
> -};
> -
> -static GLuint ushort_types_scale[4] = {
> -   PIPE_FORMAT_R16_USCALED,
> -   PIPE_FORMAT_R16G16_USCALED,
> -   PIPE_FORMAT_R16G16B16_USCALED,
> -   PIPE_FORMAT_R16G16B16A16_USCALED
> -};
> -
> -static GLuint ushort_types_int[4] = {
> -   PIPE_FORMAT_R16_UINT,
> -   PIPE_FORMAT_R16G16_UINT,
> -   PIPE_FORMAT_R16G16B16_UINT,
> -   PIPE_FORMAT_R16G16B16A16_UINT
> -};
> -
> -static GLuint short_types_norm[4] = {
> -   PIPE_FORMAT_R16_SNORM,
> -   PIPE_FORMAT_R16G16_SNORM,
> -   PIPE_FORMAT_R16G16B16_SNORM,
> -   PIPE_FORMAT_R16G16B16A16_SNORM
> -};
> -
> -static GLuint short_types_scale[4] = {
> -   PIPE_FORMAT_R16_SSCALED,
> -   PIPE_FORMAT_R16G16_SSCALED,
> -   PIPE_FORMAT_R16G16B16_SSCALED,
> -   PIPE_FORMAT_R16G16B16A16_SSCALED
> -};
> -
> -static GLuint short_types_int[4] = {
> -   PIPE_FORMAT_R16_SINT,
> -   PIPE_FORMAT_R16G16_SINT,
> -   PIPE_FORMAT_R16G16B16_SINT,
> -   PIPE_FORMAT_R16G16B16A16_SINT
> -};
> -
> -static GLuint ubyte_types_norm[4] = {
> -   PIPE_FORMAT_R8_UNORM,
> -   PIPE_FORMAT_R8G8_UNORM,
> -   PIPE_FORMAT_R8G8B8_UNORM,
> -   PIPE_FORMAT_R8G8B8A8_UNORM
> -};
> -
> -static GLuint ubyte_types_scale[4] = {
> -   PIPE_FORMAT_R8_USCALED,
> -   PIPE_FORMAT_R8G8_USCALED,
> -   PIPE_FORMAT_R8G8B8_USCALED,
> -   PIPE_FORMAT_R8G8B8A8_USCALED
> -};
> -
> -static GLuint ubyte_types_int[4] = {
> -   PIPE_FORMAT_R8_UINT,
> -   PIPE_FORMAT_R8G8_UINT,
> -   PIPE_FORMAT_R8G8B8_UINT,
> -   PIPE_FORMAT_R8G8B8A8_UINT
> -};
> -
> -static GLuint byte_types_norm[4] = {
> -   PIPE_FORMAT_R8_SNORM,
> -   PIPE_FORMAT_R8G8_SNORM,
> -   PIPE_FORMAT_R8G8B8_SNORM,
> -   PIPE_FORMAT_R8G8B8A8_SNORM
> -};
> -
> -static GLuint byte_types_scale[4] = {
> -   PIPE_FORMAT_R8_SSCALED,
> -   PIPE_FORMAT_R8G8_SSCALED,
> -   PIPE_FORMAT_R8G8B8_SSCALED,
> -   PIPE_FORMAT_R8G8B8A8_SSCALED
> -};
> -
> -static GLuint byte_types_int[4] = {
> -   PIPE_FORMAT_R8_SINT,
> -   PIPE_FORMAT_R8G8_SINT,
> -   PIPE_FORMAT_R8G8B8_SINT,
> -   PIPE_FORMAT_R8G8B8A8_SINT
> -};
> -
> -static GLuint fixed_types[4] = {
> -   PIPE_FORMAT_R32_FIXED,
> -   PIPE_FORMAT_R32G32_FIXED,
> -   PIPE_FORMAT_R32G32B32_FIXED,
> -   PIPE_FORMAT_R32G32B32A32_FIXED
> +static uint16_t vertex_formats[][4][4] = {
> +   {
> +      {
> +         PIPE_FORMAT_R8_SSCALED,
> +         PIPE_FORMAT_R8G8_SSCALED,
> +         PIPE_FORMAT_R8G8B8_SSCALED,
> +         PIPE_FORMAT_R8G8B8A8_SSCALED
> +      },
> +      {
> +         PIPE_FORMAT_R8_SNORM,
> +         PIPE_FORMAT_R8G8_SNORM,
> +         PIPE_FORMAT_R8G8B8_SNORM,
> +         PIPE_FORMAT_R8G8B8A8_SNORM
> +      },
> +      {
> +         PIPE_FORMAT_R8_SINT,
> +         PIPE_FORMAT_R8G8_SINT,
> +         PIPE_FORMAT_R8G8B8_SINT,
> +         PIPE_FORMAT_R8G8B8A8_SINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R8_USCALED,
> +         PIPE_FORMAT_R8G8_USCALED,
> +         PIPE_FORMAT_R8G8B8_USCALED,
> +         PIPE_FORMAT_R8G8B8A8_USCALED
> +      },
> +      {
> +         PIPE_FORMAT_R8_UNORM,
> +         PIPE_FORMAT_R8G8_UNORM,
> +         PIPE_FORMAT_R8G8B8_UNORM,
> +         PIPE_FORMAT_R8G8B8A8_UNORM
> +      },
> +      {
> +         PIPE_FORMAT_R8_UINT,
> +         PIPE_FORMAT_R8G8_UINT,
> +         PIPE_FORMAT_R8G8B8_UINT,
> +         PIPE_FORMAT_R8G8B8A8_UINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R16_SSCALED,
> +         PIPE_FORMAT_R16G16_SSCALED,
> +         PIPE_FORMAT_R16G16B16_SSCALED,
> +         PIPE_FORMAT_R16G16B16A16_SSCALED
> +      },
> +      {
> +         PIPE_FORMAT_R16_SNORM,
> +         PIPE_FORMAT_R16G16_SNORM,
> +         PIPE_FORMAT_R16G16B16_SNORM,
> +         PIPE_FORMAT_R16G16B16A16_SNORM
> +      },
> +      {
> +         PIPE_FORMAT_R16_SINT,
> +         PIPE_FORMAT_R16G16_SINT,
> +         PIPE_FORMAT_R16G16B16_SINT,
> +         PIPE_FORMAT_R16G16B16A16_SINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R16_USCALED,
> +         PIPE_FORMAT_R16G16_USCALED,
> +         PIPE_FORMAT_R16G16B16_USCALED,
> +         PIPE_FORMAT_R16G16B16A16_USCALED
> +      },
> +      {
> +         PIPE_FORMAT_R16_UNORM,
> +         PIPE_FORMAT_R16G16_UNORM,
> +         PIPE_FORMAT_R16G16B16_UNORM,
> +         PIPE_FORMAT_R16G16B16A16_UNORM
> +      },
> +      {
> +         PIPE_FORMAT_R16_UINT,
> +         PIPE_FORMAT_R16G16_UINT,
> +         PIPE_FORMAT_R16G16B16_UINT,
> +         PIPE_FORMAT_R16G16B16A16_UINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R32_SSCALED,
> +         PIPE_FORMAT_R32G32_SSCALED,
> +         PIPE_FORMAT_R32G32B32_SSCALED,
> +         PIPE_FORMAT_R32G32B32A32_SSCALED
> +      },
> +      {
> +         PIPE_FORMAT_R32_SNORM,
> +         PIPE_FORMAT_R32G32_SNORM,
> +         PIPE_FORMAT_R32G32B32_SNORM,
> +         PIPE_FORMAT_R32G32B32A32_SNORM
> +      },
> +      {
> +         PIPE_FORMAT_R32_SINT,
> +         PIPE_FORMAT_R32G32_SINT,
> +         PIPE_FORMAT_R32G32B32_SINT,
> +         PIPE_FORMAT_R32G32B32A32_SINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R32_USCALED,
> +         PIPE_FORMAT_R32G32_USCALED,
> +         PIPE_FORMAT_R32G32B32_USCALED,
> +         PIPE_FORMAT_R32G32B32A32_USCALED
> +      },
> +      {
> +         PIPE_FORMAT_R32_UNORM,
> +         PIPE_FORMAT_R32G32_UNORM,
> +         PIPE_FORMAT_R32G32B32_UNORM,
> +         PIPE_FORMAT_R32G32B32A32_UNORM
> +      },
> +      {
> +         PIPE_FORMAT_R32_UINT,
> +         PIPE_FORMAT_R32G32_UINT,
> +         PIPE_FORMAT_R32G32B32_UINT,
> +         PIPE_FORMAT_R32G32B32A32_UINT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R32_FLOAT,
> +         PIPE_FORMAT_R32G32_FLOAT,
> +         PIPE_FORMAT_R32G32B32_FLOAT,
> +         PIPE_FORMAT_R32G32B32A32_FLOAT
> +      },
> +      {
> +         PIPE_FORMAT_R32_FLOAT,
> +         PIPE_FORMAT_R32G32_FLOAT,
> +         PIPE_FORMAT_R32G32B32_FLOAT,
> +         PIPE_FORMAT_R32G32B32A32_FLOAT
> +      },
> +   },
> +   {{0}}, /* GL_2_BYTES */
> +   {{0}}, /* GL_3_BYTES */
> +   {{0}}, /* GL_4_BYTES */
> +   {
> +      {
> +         PIPE_FORMAT_R64_FLOAT,
> +         PIPE_FORMAT_R64G64_FLOAT,
> +         PIPE_FORMAT_R64G64B64_FLOAT,
> +         PIPE_FORMAT_R64G64B64A64_FLOAT
> +      },
> +      {
> +         PIPE_FORMAT_R64_FLOAT,
> +         PIPE_FORMAT_R64G64_FLOAT,
> +         PIPE_FORMAT_R64G64B64_FLOAT,
> +         PIPE_FORMAT_R64G64B64A64_FLOAT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R16_FLOAT,
> +         PIPE_FORMAT_R16G16_FLOAT,
> +         PIPE_FORMAT_R16G16B16_FLOAT,
> +         PIPE_FORMAT_R16G16B16A16_FLOAT
> +      },
> +      {
> +         PIPE_FORMAT_R16_FLOAT,
> +         PIPE_FORMAT_R16G16_FLOAT,
> +         PIPE_FORMAT_R16G16B16_FLOAT,
> +         PIPE_FORMAT_R16G16B16A16_FLOAT
> +      },
> +   },
> +   {
> +      {
> +         PIPE_FORMAT_R32_FIXED,
> +         PIPE_FORMAT_R32G32_FIXED,
> +         PIPE_FORMAT_R32G32B32_FIXED,
> +         PIPE_FORMAT_R32G32B32A32_FIXED
> +      },
> +      {
> +         PIPE_FORMAT_R32_FIXED,
> +         PIPE_FORMAT_R32G32_FIXED,
> +         PIPE_FORMAT_R32G32B32_FIXED,
> +         PIPE_FORMAT_R32G32B32A32_FIXED
> +      },
> +   },
>  };
>
>
>  /**
>   * Return a PIPE_FORMAT_x for the given GL datatype and size.
>   */
>  enum pipe_format
>  st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
>                        GLboolean normalized, GLboolean integer)
>  {
> -   assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
> -          type == GL_FIXED || type == GL_HALF_FLOAT ||
> -          type == GL_HALF_FLOAT_OES ||
> -          type == GL_INT_2_10_10_10_REV ||
> -          type == GL_UNSIGNED_INT_2_10_10_10_REV ||
> -          type == GL_UNSIGNED_INT_10F_11F_11F_REV);
> -   assert(size >= 1);
> -   assert(size <= 4);
> +   unsigned index;
> +
> +   assert(size >= 1 && size <= 4);
>     assert(format == GL_RGBA || format == GL_BGRA);
>
> -   if (type == GL_INT_2_10_10_10_REV ||
> -       type == GL_UNSIGNED_INT_2_10_10_10_REV) {
> -      assert(size == 4);
> -      assert(!integer);
> +   switch (type) {
> +   case GL_HALF_FLOAT_OES:
> +      type = GL_HALF_FLOAT;
> +      break;
> +
> +   case GL_INT_2_10_10_10_REV:
> +      assert(size == 4 && !integer);
>
>        if (format == GL_BGRA) {
> -         if (type == GL_INT_2_10_10_10_REV) {
> -            if (normalized)
> -               return PIPE_FORMAT_B10G10R10A2_SNORM;
> -            else
> -               return PIPE_FORMAT_B10G10R10A2_SSCALED;
> -         } else {
> -            if (normalized)
> -               return PIPE_FORMAT_B10G10R10A2_UNORM;
> -            else
> -               return PIPE_FORMAT_B10G10R10A2_USCALED;
> -         }
> +         if (normalized)
> +            return PIPE_FORMAT_B10G10R10A2_SNORM;
> +         else
> +            return PIPE_FORMAT_B10G10R10A2_SSCALED;
>        } else {
> -         if (type == GL_INT_2_10_10_10_REV) {
> -            if (normalized)
> -               return PIPE_FORMAT_R10G10B10A2_SNORM;
> -            else
> -               return PIPE_FORMAT_R10G10B10A2_SSCALED;
> -         } else {
> -            if (normalized)
> -               return PIPE_FORMAT_R10G10B10A2_UNORM;
> -            else
> -               return PIPE_FORMAT_R10G10B10A2_USCALED;
> -         }
> +         if (normalized)
> +            return PIPE_FORMAT_R10G10B10A2_SNORM;
> +         else
> +            return PIPE_FORMAT_R10G10B10A2_SSCALED;
>        }
> -   }
> +      break;
>
> -   if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
> -      assert(size == 3);
> -      assert(!integer);
> -      assert(format == GL_RGBA);
> +   case GL_UNSIGNED_INT_2_10_10_10_REV:
> +      assert(size == 4 && !integer);
>
> -      return PIPE_FORMAT_R11G11B10_FLOAT;
> -   }
> +      if (format == GL_BGRA) {
> +         if (normalized)
> +            return PIPE_FORMAT_B10G10R10A2_UNORM;
> +         else
> +            return PIPE_FORMAT_B10G10R10A2_USCALED;
> +      } else {
> +         if (normalized)
> +            return PIPE_FORMAT_R10G10B10A2_UNORM;
> +         else
> +            return PIPE_FORMAT_R10G10B10A2_USCALED;
> +      }
> +      break;
>
> -   if (format == GL_BGRA) {
> -      /* this is an odd-ball case */
> -      assert(type == GL_UNSIGNED_BYTE);
> -      assert(normalized);
> -      return PIPE_FORMAT_B8G8R8A8_UNORM;
> -   }
> +   case GL_UNSIGNED_INT_10F_11F_11F_REV:
> +      assert(size == 3 && !integer && format == GL_RGBA);
> +      return PIPE_FORMAT_R11G11B10_FLOAT;
>
> -   if (integer) {
> -      switch (type) {
> -      case GL_INT: return int_types_int[size-1];
> -      case GL_SHORT: return short_types_int[size-1];
> -      case GL_BYTE: return byte_types_int[size-1];
> -      case GL_UNSIGNED_INT: return uint_types_int[size-1];
> -      case GL_UNSIGNED_SHORT: return ushort_types_int[size-1];
> -      case GL_UNSIGNED_BYTE: return ubyte_types_int[size-1];
> -      default: assert(0); return 0;
> -      }
> -   }
> -   else if (normalized) {
> -      switch (type) {
> -      case GL_DOUBLE: return double_types[size-1];
> -      case GL_FLOAT: return float_types[size-1];
> -      case GL_HALF_FLOAT:
> -      case GL_HALF_FLOAT_OES: return half_float_types[size-1];
> -      case GL_INT: return int_types_norm[size-1];
> -      case GL_SHORT: return short_types_norm[size-1];
> -      case GL_BYTE: return byte_types_norm[size-1];
> -      case GL_UNSIGNED_INT: return uint_types_norm[size-1];
> -      case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
> -      case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
> -      case GL_FIXED: return fixed_types[size-1];
> -      default: assert(0); return 0;
> -      }
> -   }
> -   else {
> -      switch (type) {
> -      case GL_DOUBLE: return double_types[size-1];
> -      case GL_FLOAT: return float_types[size-1];
> -      case GL_HALF_FLOAT:
> -      case GL_HALF_FLOAT_OES: return half_float_types[size-1];
> -      case GL_INT: return int_types_scale[size-1];
> -      case GL_SHORT: return short_types_scale[size-1];
> -      case GL_BYTE: return byte_types_scale[size-1];
> -      case GL_UNSIGNED_INT: return uint_types_scale[size-1];
> -      case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
> -      case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
> -      case GL_FIXED: return fixed_types[size-1];
> -      default: assert(0); return 0;
> +   case GL_UNSIGNED_BYTE:
> +      if (format == GL_BGRA) {
> +         /* this is an odd-ball case */
> +         assert(normalized);
> +         return PIPE_FORMAT_B8G8R8A8_UNORM;
>        }
> +      break;
>     }
> -   return PIPE_FORMAT_NONE; /* silence compiler warning */
> +
> +   index = integer*2 + normalized;
> +   assert(index <= 2);
> +   assert(type >= GL_BYTE && type <= GL_FIXED);
> +   return vertex_formats[type - GL_BYTE][index][size-1];
>  }
>
>  static const struct gl_vertex_array *
>  get_client_array(const struct st_vertex_program *vp,
>                   const struct gl_vertex_array **arrays,
>                   int attr)
>  {
>     const GLuint mesaAttr = vp->index_to_input[attr];
>     /* st_program uses 0xffffffff to denote a double placeholder attribute */
>     if (mesaAttr == ST_DOUBLE_ATTRIB_PLACEHOLDER)
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list