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

Emil Velikov emil.l.velikov at gmail.com
Thu Oct 8 10:09:27 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.

Move VARYING_SLOT_MAX macro to shader_enums.h

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/glsl/shader_enums.c | 65 --------------------------------------------
 src/glsl/shader_enums.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/mtypes.h  |  1 -
 3 files changed, 71 insertions(+), 67 deletions(-)

diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
index 4abdc328..61c1fa6 100644
--- a/src/glsl/shader_enums.c
+++ b/src/glsl/shader_enums.c
@@ -32,71 +32,6 @@
 #define ENUM(x) [x] = #x
 #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
 
-const char * gl_varying_slot_name(gl_varying_slot slot)
-{
-   static const char *names[] = {
-      ENUM(VARYING_SLOT_POS),
-      ENUM(VARYING_SLOT_COL0),
-      ENUM(VARYING_SLOT_COL1),
-      ENUM(VARYING_SLOT_FOGC),
-      ENUM(VARYING_SLOT_TEX0),
-      ENUM(VARYING_SLOT_TEX1),
-      ENUM(VARYING_SLOT_TEX2),
-      ENUM(VARYING_SLOT_TEX3),
-      ENUM(VARYING_SLOT_TEX4),
-      ENUM(VARYING_SLOT_TEX5),
-      ENUM(VARYING_SLOT_TEX6),
-      ENUM(VARYING_SLOT_TEX7),
-      ENUM(VARYING_SLOT_PSIZ),
-      ENUM(VARYING_SLOT_BFC0),
-      ENUM(VARYING_SLOT_BFC1),
-      ENUM(VARYING_SLOT_EDGE),
-      ENUM(VARYING_SLOT_CLIP_VERTEX),
-      ENUM(VARYING_SLOT_CLIP_DIST0),
-      ENUM(VARYING_SLOT_CLIP_DIST1),
-      ENUM(VARYING_SLOT_PRIMITIVE_ID),
-      ENUM(VARYING_SLOT_LAYER),
-      ENUM(VARYING_SLOT_VIEWPORT),
-      ENUM(VARYING_SLOT_FACE),
-      ENUM(VARYING_SLOT_PNTC),
-      ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
-      ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
-      ENUM(VARYING_SLOT_VAR0),
-      ENUM(VARYING_SLOT_VAR1),
-      ENUM(VARYING_SLOT_VAR2),
-      ENUM(VARYING_SLOT_VAR3),
-      ENUM(VARYING_SLOT_VAR4),
-      ENUM(VARYING_SLOT_VAR5),
-      ENUM(VARYING_SLOT_VAR6),
-      ENUM(VARYING_SLOT_VAR7),
-      ENUM(VARYING_SLOT_VAR8),
-      ENUM(VARYING_SLOT_VAR9),
-      ENUM(VARYING_SLOT_VAR10),
-      ENUM(VARYING_SLOT_VAR11),
-      ENUM(VARYING_SLOT_VAR12),
-      ENUM(VARYING_SLOT_VAR13),
-      ENUM(VARYING_SLOT_VAR14),
-      ENUM(VARYING_SLOT_VAR15),
-      ENUM(VARYING_SLOT_VAR16),
-      ENUM(VARYING_SLOT_VAR17),
-      ENUM(VARYING_SLOT_VAR18),
-      ENUM(VARYING_SLOT_VAR19),
-      ENUM(VARYING_SLOT_VAR20),
-      ENUM(VARYING_SLOT_VAR21),
-      ENUM(VARYING_SLOT_VAR22),
-      ENUM(VARYING_SLOT_VAR23),
-      ENUM(VARYING_SLOT_VAR24),
-      ENUM(VARYING_SLOT_VAR25),
-      ENUM(VARYING_SLOT_VAR26),
-      ENUM(VARYING_SLOT_VAR27),
-      ENUM(VARYING_SLOT_VAR28),
-      ENUM(VARYING_SLOT_VAR29),
-      ENUM(VARYING_SLOT_VAR30),
-      ENUM(VARYING_SLOT_VAR31),
-   };
-   return NAME(slot);
-}
-
 const char * gl_system_value_name(gl_system_value sysval)
 {
    static const char *names[] = {
diff --git a/src/glsl/shader_enums.h b/src/glsl/shader_enums.h
index 7ea953b..9afbb8d 100644
--- a/src/glsl/shader_enums.h
+++ b/src/glsl/shader_enums.h
@@ -293,7 +293,77 @@ typedef enum
    VARYING_SLOT_VAR31,
 } gl_varying_slot;
 
-const char * gl_varying_slot_name(gl_varying_slot slot);
+#define VARYING_SLOT_MAX (VARYING_SLOT_VAR31 + 1)
+
+static const char *gl_varying_slot_names[] = {
+   ENUM(VARYING_SLOT_POS),
+   ENUM(VARYING_SLOT_COL0),
+   ENUM(VARYING_SLOT_COL1),
+   ENUM(VARYING_SLOT_FOGC),
+   ENUM(VARYING_SLOT_TEX0),
+   ENUM(VARYING_SLOT_TEX1),
+   ENUM(VARYING_SLOT_TEX2),
+   ENUM(VARYING_SLOT_TEX3),
+   ENUM(VARYING_SLOT_TEX4),
+   ENUM(VARYING_SLOT_TEX5),
+   ENUM(VARYING_SLOT_TEX6),
+   ENUM(VARYING_SLOT_TEX7),
+   ENUM(VARYING_SLOT_PSIZ),
+   ENUM(VARYING_SLOT_BFC0),
+   ENUM(VARYING_SLOT_BFC1),
+   ENUM(VARYING_SLOT_EDGE),
+   ENUM(VARYING_SLOT_CLIP_VERTEX),
+   ENUM(VARYING_SLOT_CLIP_DIST0),
+   ENUM(VARYING_SLOT_CLIP_DIST1),
+   ENUM(VARYING_SLOT_PRIMITIVE_ID),
+   ENUM(VARYING_SLOT_LAYER),
+   ENUM(VARYING_SLOT_VIEWPORT),
+   ENUM(VARYING_SLOT_FACE),
+   ENUM(VARYING_SLOT_PNTC),
+   ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
+   ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
+   ENUM(VARYING_SLOT_VAR0),
+   ENUM(VARYING_SLOT_VAR1),
+   ENUM(VARYING_SLOT_VAR2),
+   ENUM(VARYING_SLOT_VAR3),
+   ENUM(VARYING_SLOT_VAR4),
+   ENUM(VARYING_SLOT_VAR5),
+   ENUM(VARYING_SLOT_VAR6),
+   ENUM(VARYING_SLOT_VAR7),
+   ENUM(VARYING_SLOT_VAR8),
+   ENUM(VARYING_SLOT_VAR9),
+   ENUM(VARYING_SLOT_VAR10),
+   ENUM(VARYING_SLOT_VAR11),
+   ENUM(VARYING_SLOT_VAR12),
+   ENUM(VARYING_SLOT_VAR13),
+   ENUM(VARYING_SLOT_VAR14),
+   ENUM(VARYING_SLOT_VAR15),
+   ENUM(VARYING_SLOT_VAR16),
+   ENUM(VARYING_SLOT_VAR17),
+   ENUM(VARYING_SLOT_VAR18),
+   ENUM(VARYING_SLOT_VAR19),
+   ENUM(VARYING_SLOT_VAR20),
+   ENUM(VARYING_SLOT_VAR21),
+   ENUM(VARYING_SLOT_VAR22),
+   ENUM(VARYING_SLOT_VAR23),
+   ENUM(VARYING_SLOT_VAR24),
+   ENUM(VARYING_SLOT_VAR25),
+   ENUM(VARYING_SLOT_VAR26),
+   ENUM(VARYING_SLOT_VAR27),
+   ENUM(VARYING_SLOT_VAR28),
+   ENUM(VARYING_SLOT_VAR29),
+   ENUM(VARYING_SLOT_VAR30),
+   ENUM(VARYING_SLOT_VAR31),
+};
+
+static inline const char *gl_varying_slot_name(gl_varying_slot slot)
+{
+   STATIC_ASSERT(ARRAY_SIZE(gl_varying_slot_names) == VARYING_SLOT_MAX);
+   if (slot < ARRAY_SIZE(gl_varying_slot_names))
+      return gl_varying_slot_names[slot];
+   else
+      return "UNKNOWN";
+}
 
 /**
  * Bitflags for varying slots.
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 288d757..00a4edc 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -94,7 +94,6 @@ struct vbo_context;
 #define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
 #define PRIM_UNKNOWN             (PRIM_MAX + 2)
 
-#define VARYING_SLOT_MAX	(VARYING_SLOT_VAR0 + MAX_VARYING)
 #define VARYING_SLOT_PATCH0	(VARYING_SLOT_MAX)
 #define VARYING_SLOT_TESS_MAX	(VARYING_SLOT_PATCH0 + MAX_VARYING)
 #define FRAG_RESULT_MAX		(FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
-- 
2.5.0



More information about the mesa-dev mailing list