[Mesa-dev] [PATCH 03/11] glsl: shader-enum to name debug fxns

Rob Clark robdclark at gmail.com
Sun Sep 13 08:51:50 PDT 2015


From: Rob Clark <robclark at freedesktop.org>

Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
 src/Makefile.am           |   1 +
 src/glsl/shader_enums.c   | 202 ++++++++++++++++++++++++++++++++++++++++++++++
 src/glsl/shader_enums.h   |  53 ++++++++++++
 src/mesa/Makefile.sources |   4 +-
 4 files changed, 259 insertions(+), 1 deletion(-)
 create mode 100644 src/glsl/shader_enums.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 0d49bcd..9e15cca 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,7 @@ AM_CPPFLAGS = \
 noinst_LTLIBRARIES = libglsl_util.la
 
 libglsl_util_la_SOURCES = \
+	glsl/shader_enums.c \
 	mesa/main/imports.c \
 	mesa/program/prog_hash_table.c \
 	mesa/program/symbol_table.c \
diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
new file mode 100644
index 0000000..1c45a40
--- /dev/null
+++ b/src/glsl/shader_enums.c
@@ -0,0 +1,202 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright © 2015 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rob Clark <robclark at freedesktop.org>
+ */
+
+#include "glsl/shader_enums.h"
+#include "util/macros.h"
+
+#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[] = {
+      ENUM(VERT_ATTRIB_POS),
+      ENUM(VERT_ATTRIB_WEIGHT),
+      ENUM(VERT_ATTRIB_NORMAL),
+      ENUM(VERT_ATTRIB_COLOR0),
+      ENUM(VERT_ATTRIB_COLOR1),
+      ENUM(VERT_ATTRIB_FOG),
+      ENUM(VERT_ATTRIB_COLOR_INDEX),
+      ENUM(VERT_ATTRIB_EDGEFLAG),
+      ENUM(VERT_ATTRIB_TEX0),
+      ENUM(VERT_ATTRIB_TEX1),
+      ENUM(VERT_ATTRIB_TEX2),
+      ENUM(VERT_ATTRIB_TEX3),
+      ENUM(VERT_ATTRIB_TEX4),
+      ENUM(VERT_ATTRIB_TEX5),
+      ENUM(VERT_ATTRIB_TEX6),
+      ENUM(VERT_ATTRIB_TEX7),
+      ENUM(VERT_ATTRIB_POINT_SIZE),
+      ENUM(VERT_ATTRIB_GENERIC0),
+      ENUM(VERT_ATTRIB_GENERIC1),
+      ENUM(VERT_ATTRIB_GENERIC2),
+      ENUM(VERT_ATTRIB_GENERIC3),
+      ENUM(VERT_ATTRIB_GENERIC4),
+      ENUM(VERT_ATTRIB_GENERIC5),
+      ENUM(VERT_ATTRIB_GENERIC6),
+      ENUM(VERT_ATTRIB_GENERIC7),
+      ENUM(VERT_ATTRIB_GENERIC8),
+      ENUM(VERT_ATTRIB_GENERIC9),
+      ENUM(VERT_ATTRIB_GENERIC10),
+      ENUM(VERT_ATTRIB_GENERIC11),
+      ENUM(VERT_ATTRIB_GENERIC12),
+      ENUM(VERT_ATTRIB_GENERIC13),
+      ENUM(VERT_ATTRIB_GENERIC14),
+      ENUM(VERT_ATTRIB_GENERIC15),
+   };
+   return NAME(attrib);
+}
+
+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[] = {
+     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),
+   };
+   return NAME(sysval);
+}
+
+const char * glsl_interp_qualifier_name(enum glsl_interp_qualifier qual)
+{
+   static const char *names[] = {
+      ENUM(INTERP_QUALIFIER_NONE),
+      ENUM(INTERP_QUALIFIER_SMOOTH),
+      ENUM(INTERP_QUALIFIER_FLAT),
+      ENUM(INTERP_QUALIFIER_NOPERSPECTIVE),
+   };
+   return NAME(qual);
+}
+
+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 9bb163f..d054b87 100644
--- a/src/glsl/shader_enums.h
+++ b/src/glsl/shader_enums.h
@@ -43,6 +43,8 @@ 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)
 
 
@@ -91,6 +93,8 @@ typedef enum
    VERT_ATTRIB_MAX = 33
 } gl_vert_attrib;
 
+const char * gl_vert_attrib_name(gl_vert_attrib attrib);
+
 /**
  * Symbolic constats to help iterating over
  * specific blocks of vertex attributes.
@@ -193,8 +197,43 @@ typedef enum
    VARYING_SLOT_TESS_LEVEL_OUTER, /* Only appears as TCS output. */
    VARYING_SLOT_TESS_LEVEL_INNER, /* Only appears as TCS output. */
    VARYING_SLOT_VAR0, /* First generic varying slot */
+   /* the remaining are simply for the benefit of gl_varying_slot_name()
+    * and not to be construed as an upper bound:
+    */
+   VARYING_SLOT_VAR1,
+   VARYING_SLOT_VAR2,
+   VARYING_SLOT_VAR3,
+   VARYING_SLOT_VAR4,
+   VARYING_SLOT_VAR5,
+   VARYING_SLOT_VAR6,
+   VARYING_SLOT_VAR7,
+   VARYING_SLOT_VAR8,
+   VARYING_SLOT_VAR9,
+   VARYING_SLOT_VAR10,
+   VARYING_SLOT_VAR11,
+   VARYING_SLOT_VAR12,
+   VARYING_SLOT_VAR13,
+   VARYING_SLOT_VAR14,
+   VARYING_SLOT_VAR15,
+   VARYING_SLOT_VAR16,
+   VARYING_SLOT_VAR17,
+   VARYING_SLOT_VAR18,
+   VARYING_SLOT_VAR19,
+   VARYING_SLOT_VAR20,
+   VARYING_SLOT_VAR21,
+   VARYING_SLOT_VAR22,
+   VARYING_SLOT_VAR23,
+   VARYING_SLOT_VAR24,
+   VARYING_SLOT_VAR25,
+   VARYING_SLOT_VAR26,
+   VARYING_SLOT_VAR27,
+   VARYING_SLOT_VAR28,
+   VARYING_SLOT_VAR29,
+   VARYING_SLOT_VAR30,
+   VARYING_SLOT_VAR31,
 } gl_varying_slot;
 
+const char * gl_varying_slot_name(gl_varying_slot slot);
 
 /**
  * Bitflags for varying slots.
@@ -366,6 +405,7 @@ typedef enum
    SYSTEM_VALUE_MAX             /**< Number of values */
 } gl_system_value;
 
+const char * gl_system_value_name(gl_system_value sysval);
 
 /**
  * The possible interpolation qualifiers that can be applied to a fragment
@@ -383,6 +423,8 @@ enum glsl_interp_qualifier
    INTERP_QUALIFIER_COUNT /**< Number of interpolation qualifiers */
 };
 
+const char * glsl_interp_qualifier_name(enum glsl_interp_qualifier qual);
+
 /**
  * Fragment program results
  */
@@ -399,8 +441,19 @@ typedef enum
    /* FRAG_RESULT_DATAn are the per-render-target (GLSL gl_FragData[n]
     * or ARB_fragment_program fragment.color[n]) color results.  If
     * any are written, FRAG_RESULT_COLOR will not be written.
+    * FRAG_RESULT_DATA1 and up are simply for the benefit of
+    * gl_frag_result_name() and not to be construed as an upper bound
     */
    FRAG_RESULT_DATA0 = 4,
+   FRAG_RESULT_DATA1,
+   FRAG_RESULT_DATA2,
+   FRAG_RESULT_DATA3,
+   FRAG_RESULT_DATA4,
+   FRAG_RESULT_DATA5,
+   FRAG_RESULT_DATA6,
+   FRAG_RESULT_DATA7,
 } gl_frag_result;
 
+const char * gl_frag_result_name(gl_frag_result result);
+
 #endif /* SHADER_ENUMS_H */
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index ed9848c..2a719a0 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -523,7 +523,9 @@ PROGRAM_FILES = \
 	program/sampler.h \
 	program/string_to_uint_map.cpp \
 	program/symbol_table.c \
-	program/symbol_table.h
+	program/symbol_table.h \
+	../glsl/shader_enums.c \
+	../glsl/shader_enums.h
 
 PROGRAM_NIR_FILES = \
 	program/prog_to_nir.c \
-- 
2.4.3



More information about the mesa-dev mailing list