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

Emil Velikov emil.l.velikov at gmail.com
Thu Oct 8 10:09:30 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 FRAG_RESULT_MAX macro to shader_enums.h

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

diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
index 1e8ea66..f998cb8 100644
--- a/src/glsl/shader_enums.c
+++ b/src/glsl/shader_enums.c
@@ -32,21 +32,3 @@
 #define ENUM(x) [x] = #x
 #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
 
-const char * gl_frag_result_name(gl_frag_result result)
-{
-   static const char *names[] = {
-      ENUM(FRAG_RESULT_DEPTH),
-      ENUM(FRAG_RESULT_STENCIL),
-      ENUM(FRAG_RESULT_COLOR),
-      ENUM(FRAG_RESULT_SAMPLE_MASK),
-      ENUM(FRAG_RESULT_DATA0),
-      ENUM(FRAG_RESULT_DATA1),
-      ENUM(FRAG_RESULT_DATA2),
-      ENUM(FRAG_RESULT_DATA3),
-      ENUM(FRAG_RESULT_DATA4),
-      ENUM(FRAG_RESULT_DATA5),
-      ENUM(FRAG_RESULT_DATA6),
-      ENUM(FRAG_RESULT_DATA7),
-   };
-   return NAME(result);
-}
diff --git a/src/glsl/shader_enums.h b/src/glsl/shader_enums.h
index 0305f5d..7d4e573 100644
--- a/src/glsl/shader_enums.h
+++ b/src/glsl/shader_enums.h
@@ -643,7 +643,31 @@ typedef enum
    FRAG_RESULT_DATA7,
 } gl_frag_result;
 
-const char * gl_frag_result_name(gl_frag_result result);
+#define FRAG_RESULT_MAX (FRAG_RESULT_DATA7 + 1)
+
+static const char *gl_frag_result_names[] = {
+   ENUM(FRAG_RESULT_DEPTH),
+   ENUM(FRAG_RESULT_STENCIL),
+   ENUM(FRAG_RESULT_COLOR),
+   ENUM(FRAG_RESULT_SAMPLE_MASK),
+   ENUM(FRAG_RESULT_DATA0),
+   ENUM(FRAG_RESULT_DATA1),
+   ENUM(FRAG_RESULT_DATA2),
+   ENUM(FRAG_RESULT_DATA3),
+   ENUM(FRAG_RESULT_DATA4),
+   ENUM(FRAG_RESULT_DATA5),
+   ENUM(FRAG_RESULT_DATA6),
+   ENUM(FRAG_RESULT_DATA7),
+};
+
+static inline const char *gl_frag_result_name(gl_frag_result result)
+{
+   STATIC_ASSERT(ARRAY_SIZE(gl_frag_result_names) == FRAG_RESULT_MAX);
+   if (result < ARRAY_SIZE(gl_frag_result_names))
+      return gl_frag_result_names[result];
+   else
+      return "UNKNOWN";
+}
 
 #undef ENUM
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 00a4edc..929fe64 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -96,7 +96,6 @@ struct vbo_context;
 
 #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)
 
 /**
  * Determine if the given gl_varying_slot appears in the fragment shader.
-- 
2.5.0



More information about the mesa-dev mailing list