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

Emil Velikov emil.l.velikov at gmail.com
Thu Oct 8 10:09:28 PDT 2015


This is a trivial enough function that can live in the header. While
we're here, add a STATIC_ASSERT for good measure.

Add the missing SYSTEM_VALUE_NUM_WORK_GROUPS enum.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/glsl/shader_enums.c | 24 ------------------------
 src/glsl/shader_enums.h | 30 +++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
index 61c1fa6..9b9ec2b 100644
--- a/src/glsl/shader_enums.c
+++ b/src/glsl/shader_enums.c
@@ -32,30 +32,6 @@
 #define ENUM(x) [x] = #x
 #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
 
-const char * gl_system_value_name(gl_system_value sysval)
-{
-   static const char *names[] = {
-     ENUM(SYSTEM_VALUE_VERTEX_ID),
-     ENUM(SYSTEM_VALUE_INSTANCE_ID),
-     ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
-     ENUM(SYSTEM_VALUE_BASE_VERTEX),
-     ENUM(SYSTEM_VALUE_INVOCATION_ID),
-     ENUM(SYSTEM_VALUE_FRONT_FACE),
-     ENUM(SYSTEM_VALUE_SAMPLE_ID),
-     ENUM(SYSTEM_VALUE_SAMPLE_POS),
-     ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
-     ENUM(SYSTEM_VALUE_TESS_COORD),
-     ENUM(SYSTEM_VALUE_VERTICES_IN),
-     ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
-     ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
-     ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
-     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
-     ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
-     ENUM(SYSTEM_VALUE_VERTEX_CNT),
-   };
-   return NAME(sysval);
-}
-
 const char * glsl_interp_qualifier_name(enum glsl_interp_qualifier qual)
 {
    static const char *names[] = {
diff --git a/src/glsl/shader_enums.h b/src/glsl/shader_enums.h
index 9afbb8d..a560017 100644
--- a/src/glsl/shader_enums.h
+++ b/src/glsl/shader_enums.h
@@ -552,7 +552,35 @@ typedef enum
    SYSTEM_VALUE_MAX             /**< Number of values */
 } gl_system_value;
 
-const char * gl_system_value_name(gl_system_value sysval);
+static const char *gl_system_value_names[] = {
+   ENUM(SYSTEM_VALUE_VERTEX_ID),
+   ENUM(SYSTEM_VALUE_INSTANCE_ID),
+   ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
+   ENUM(SYSTEM_VALUE_BASE_VERTEX),
+   ENUM(SYSTEM_VALUE_INVOCATION_ID),
+   ENUM(SYSTEM_VALUE_FRONT_FACE),
+   ENUM(SYSTEM_VALUE_SAMPLE_ID),
+   ENUM(SYSTEM_VALUE_SAMPLE_POS),
+   ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
+   ENUM(SYSTEM_VALUE_TESS_COORD),
+   ENUM(SYSTEM_VALUE_VERTICES_IN),
+   ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
+   ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
+   ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
+   ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
+   ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
+   ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
+   ENUM(SYSTEM_VALUE_VERTEX_CNT),
+};
+
+static inline const char *gl_system_value_name(gl_system_value sysval)
+{
+   STATIC_ASSERT(ARRAY_SIZE(gl_system_value_names) == SYSTEM_VALUE_MAX);
+   if (sysval < ARRAY_SIZE(gl_system_value_names))
+      return gl_system_value_names[sysval];
+   else
+      return "UNKNOWN";
+}
 
 /**
  * The possible interpolation qualifiers that can be applied to a fragment
-- 
2.5.0



More information about the mesa-dev mailing list