[Mesa-dev] [PATCH 1/7] glsl: move gl_shader_stage_name() definition to shader_enums.h

Ilia Mirkin imirkin at alum.mit.edu
Thu Oct 8 10:08:04 PDT 2015


On Thu, Oct 8, 2015 at 1:09 PM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> This is a trivial enough function that can live in the header. While
> we're here, add a STATIC_ASSERT for good measure.
>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
>  src/glsl/shader_enums.c | 13 -------------
>  src/glsl/shader_enums.h | 23 +++++++++++++++++++++--
>  2 files changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
> index c196b79..b3da3e9 100644
> --- a/src/glsl/shader_enums.c
> +++ b/src/glsl/shader_enums.c
> @@ -32,19 +32,6 @@
>  #define ENUM(x) [x] = #x
>  #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
>
> -const char * gl_shader_stage_name(gl_shader_stage stage)
> -{
> -   static const char *names[] = {
> -      ENUM(MESA_SHADER_VERTEX),
> -      ENUM(MESA_SHADER_TESS_CTRL),
> -      ENUM(MESA_SHADER_TESS_EVAL),
> -      ENUM(MESA_SHADER_GEOMETRY),
> -      ENUM(MESA_SHADER_FRAGMENT),
> -      ENUM(MESA_SHADER_COMPUTE),
> -   };
> -   return NAME(stage);
> -}
> -
>  const char * gl_vert_attrib_name(gl_vert_attrib attrib)
>  {
>     static const char *names[] = {
> diff --git a/src/glsl/shader_enums.h b/src/glsl/shader_enums.h
> index 2a5d2c5..fbd2744 100644
> --- a/src/glsl/shader_enums.h
> +++ b/src/glsl/shader_enums.h
> @@ -43,10 +43,27 @@ typedef enum
>     MESA_SHADER_COMPUTE = 5,
>  } gl_shader_stage;
>
> -const char * gl_shader_stage_name(gl_shader_stage stage);
> -
>  #define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
>
> +#define ENUM(x) [x] = #x
> +
> +static const char *gl_shader_stage_names[] = {
> +   ENUM(MESA_SHADER_VERTEX),
> +   ENUM(MESA_SHADER_TESS_CTRL),
> +   ENUM(MESA_SHADER_TESS_EVAL),
> +   ENUM(MESA_SHADER_GEOMETRY),
> +   ENUM(MESA_SHADER_FRAGMENT),
> +   ENUM(MESA_SHADER_COMPUTE),
> +};

Won't this bloat the binary by including this in every object file? I
don't know that the array will get merged. (The strings will though.)
Normally these things live in c files so that they're stored in only
one object.

> +
> +static inline const char *gl_shader_stage_name(gl_shader_stage stage)
> +{
> +   STATIC_ASSERT(ARRAY_SIZE(gl_shader_stage_names) == MESA_SHADER_STAGES);
> +   if (stage < ARRAY_SIZE(gl_shader_stage_names))
> +      return gl_shader_stage_names[stage];
> +   else
> +      return "UNKNOWN";
> +}
>
>  /**
>   * Indexes for vertex program attributes.
> @@ -473,4 +490,6 @@ typedef enum
>
>  const char * gl_frag_result_name(gl_frag_result result);
>
> +#undef ENUM
> +
>  #endif /* SHADER_ENUMS_H */
> --
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list