shader_enums.c revision 01e04c3f
1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright © 2015 Red Hat 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 * IN THE SOFTWARE. 24 * 25 * Authors: 26 * Rob Clark <robclark@freedesktop.org> 27 */ 28 29#include "shader_enums.h" 30#include "util/macros.h" 31#include "mesa/main/config.h" 32 33#define ENUM(x) [x] = #x 34#define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN") 35 36const char * 37gl_shader_stage_name(gl_shader_stage stage) 38{ 39 static const char *names[] = { 40 ENUM(MESA_SHADER_VERTEX), 41 ENUM(MESA_SHADER_TESS_CTRL), 42 ENUM(MESA_SHADER_TESS_EVAL), 43 ENUM(MESA_SHADER_GEOMETRY), 44 ENUM(MESA_SHADER_FRAGMENT), 45 ENUM(MESA_SHADER_COMPUTE), 46 }; 47 STATIC_ASSERT(ARRAY_SIZE(names) == MESA_SHADER_STAGES); 48 return NAME(stage); 49} 50 51/** 52 * Translate a gl_shader_stage to a short shader stage name for debug 53 * printouts and error messages. 54 */ 55const char * 56_mesa_shader_stage_to_string(unsigned stage) 57{ 58 switch (stage) { 59 case MESA_SHADER_VERTEX: return "vertex"; 60 case MESA_SHADER_FRAGMENT: return "fragment"; 61 case MESA_SHADER_GEOMETRY: return "geometry"; 62 case MESA_SHADER_COMPUTE: return "compute"; 63 case MESA_SHADER_TESS_CTRL: return "tessellation control"; 64 case MESA_SHADER_TESS_EVAL: return "tessellation evaluation"; 65 } 66 67 unreachable("Unknown shader stage."); 68} 69 70/** 71 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS) 72 * for debug printouts and error messages. 73 */ 74const char * 75_mesa_shader_stage_to_abbrev(unsigned stage) 76{ 77 switch (stage) { 78 case MESA_SHADER_VERTEX: return "VS"; 79 case MESA_SHADER_FRAGMENT: return "FS"; 80 case MESA_SHADER_GEOMETRY: return "GS"; 81 case MESA_SHADER_COMPUTE: return "CS"; 82 case MESA_SHADER_TESS_CTRL: return "TCS"; 83 case MESA_SHADER_TESS_EVAL: return "TES"; 84 } 85 86 unreachable("Unknown shader stage."); 87} 88 89const char * 90gl_vert_attrib_name(gl_vert_attrib attrib) 91{ 92 static const char *names[] = { 93 ENUM(VERT_ATTRIB_POS), 94 ENUM(VERT_ATTRIB_NORMAL), 95 ENUM(VERT_ATTRIB_COLOR0), 96 ENUM(VERT_ATTRIB_COLOR1), 97 ENUM(VERT_ATTRIB_FOG), 98 ENUM(VERT_ATTRIB_COLOR_INDEX), 99 ENUM(VERT_ATTRIB_EDGEFLAG), 100 ENUM(VERT_ATTRIB_TEX0), 101 ENUM(VERT_ATTRIB_TEX1), 102 ENUM(VERT_ATTRIB_TEX2), 103 ENUM(VERT_ATTRIB_TEX3), 104 ENUM(VERT_ATTRIB_TEX4), 105 ENUM(VERT_ATTRIB_TEX5), 106 ENUM(VERT_ATTRIB_TEX6), 107 ENUM(VERT_ATTRIB_TEX7), 108 ENUM(VERT_ATTRIB_POINT_SIZE), 109 ENUM(VERT_ATTRIB_GENERIC0), 110 ENUM(VERT_ATTRIB_GENERIC1), 111 ENUM(VERT_ATTRIB_GENERIC2), 112 ENUM(VERT_ATTRIB_GENERIC3), 113 ENUM(VERT_ATTRIB_GENERIC4), 114 ENUM(VERT_ATTRIB_GENERIC5), 115 ENUM(VERT_ATTRIB_GENERIC6), 116 ENUM(VERT_ATTRIB_GENERIC7), 117 ENUM(VERT_ATTRIB_GENERIC8), 118 ENUM(VERT_ATTRIB_GENERIC9), 119 ENUM(VERT_ATTRIB_GENERIC10), 120 ENUM(VERT_ATTRIB_GENERIC11), 121 ENUM(VERT_ATTRIB_GENERIC12), 122 ENUM(VERT_ATTRIB_GENERIC13), 123 ENUM(VERT_ATTRIB_GENERIC14), 124 ENUM(VERT_ATTRIB_GENERIC15), 125 }; 126 STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX); 127 return NAME(attrib); 128} 129 130const char * 131gl_varying_slot_name(gl_varying_slot slot) 132{ 133 static const char *names[] = { 134 ENUM(VARYING_SLOT_POS), 135 ENUM(VARYING_SLOT_COL0), 136 ENUM(VARYING_SLOT_COL1), 137 ENUM(VARYING_SLOT_FOGC), 138 ENUM(VARYING_SLOT_TEX0), 139 ENUM(VARYING_SLOT_TEX1), 140 ENUM(VARYING_SLOT_TEX2), 141 ENUM(VARYING_SLOT_TEX3), 142 ENUM(VARYING_SLOT_TEX4), 143 ENUM(VARYING_SLOT_TEX5), 144 ENUM(VARYING_SLOT_TEX6), 145 ENUM(VARYING_SLOT_TEX7), 146 ENUM(VARYING_SLOT_PSIZ), 147 ENUM(VARYING_SLOT_BFC0), 148 ENUM(VARYING_SLOT_BFC1), 149 ENUM(VARYING_SLOT_EDGE), 150 ENUM(VARYING_SLOT_CLIP_VERTEX), 151 ENUM(VARYING_SLOT_CLIP_DIST0), 152 ENUM(VARYING_SLOT_CLIP_DIST1), 153 ENUM(VARYING_SLOT_CULL_DIST0), 154 ENUM(VARYING_SLOT_CULL_DIST1), 155 ENUM(VARYING_SLOT_PRIMITIVE_ID), 156 ENUM(VARYING_SLOT_LAYER), 157 ENUM(VARYING_SLOT_VIEWPORT), 158 ENUM(VARYING_SLOT_FACE), 159 ENUM(VARYING_SLOT_PNTC), 160 ENUM(VARYING_SLOT_TESS_LEVEL_OUTER), 161 ENUM(VARYING_SLOT_TESS_LEVEL_INNER), 162 ENUM(VARYING_SLOT_BOUNDING_BOX0), 163 ENUM(VARYING_SLOT_BOUNDING_BOX1), 164 ENUM(VARYING_SLOT_VIEW_INDEX), 165 ENUM(VARYING_SLOT_VAR0), 166 ENUM(VARYING_SLOT_VAR1), 167 ENUM(VARYING_SLOT_VAR2), 168 ENUM(VARYING_SLOT_VAR3), 169 ENUM(VARYING_SLOT_VAR4), 170 ENUM(VARYING_SLOT_VAR5), 171 ENUM(VARYING_SLOT_VAR6), 172 ENUM(VARYING_SLOT_VAR7), 173 ENUM(VARYING_SLOT_VAR8), 174 ENUM(VARYING_SLOT_VAR9), 175 ENUM(VARYING_SLOT_VAR10), 176 ENUM(VARYING_SLOT_VAR11), 177 ENUM(VARYING_SLOT_VAR12), 178 ENUM(VARYING_SLOT_VAR13), 179 ENUM(VARYING_SLOT_VAR14), 180 ENUM(VARYING_SLOT_VAR15), 181 ENUM(VARYING_SLOT_VAR16), 182 ENUM(VARYING_SLOT_VAR17), 183 ENUM(VARYING_SLOT_VAR18), 184 ENUM(VARYING_SLOT_VAR19), 185 ENUM(VARYING_SLOT_VAR20), 186 ENUM(VARYING_SLOT_VAR21), 187 ENUM(VARYING_SLOT_VAR22), 188 ENUM(VARYING_SLOT_VAR23), 189 ENUM(VARYING_SLOT_VAR24), 190 ENUM(VARYING_SLOT_VAR25), 191 ENUM(VARYING_SLOT_VAR26), 192 ENUM(VARYING_SLOT_VAR27), 193 ENUM(VARYING_SLOT_VAR28), 194 ENUM(VARYING_SLOT_VAR29), 195 ENUM(VARYING_SLOT_VAR30), 196 ENUM(VARYING_SLOT_VAR31), 197 }; 198 STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX); 199 return NAME(slot); 200} 201 202const char * 203gl_system_value_name(gl_system_value sysval) 204{ 205 static const char *names[] = { 206 ENUM(SYSTEM_VALUE_SUBGROUP_SIZE), 207 ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION), 208 ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK), 209 ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK), 210 ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK), 211 ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK), 212 ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK), 213 ENUM(SYSTEM_VALUE_NUM_SUBGROUPS), 214 ENUM(SYSTEM_VALUE_SUBGROUP_ID), 215 ENUM(SYSTEM_VALUE_VERTEX_ID), 216 ENUM(SYSTEM_VALUE_INSTANCE_ID), 217 ENUM(SYSTEM_VALUE_INSTANCE_INDEX), 218 ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE), 219 ENUM(SYSTEM_VALUE_BASE_VERTEX), 220 ENUM(SYSTEM_VALUE_FIRST_VERTEX), 221 ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW), 222 ENUM(SYSTEM_VALUE_BASE_INSTANCE), 223 ENUM(SYSTEM_VALUE_DRAW_ID), 224 ENUM(SYSTEM_VALUE_INVOCATION_ID), 225 ENUM(SYSTEM_VALUE_FRAG_COORD), 226 ENUM(SYSTEM_VALUE_FRONT_FACE), 227 ENUM(SYSTEM_VALUE_SAMPLE_ID), 228 ENUM(SYSTEM_VALUE_SAMPLE_POS), 229 ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN), 230 ENUM(SYSTEM_VALUE_HELPER_INVOCATION), 231 ENUM(SYSTEM_VALUE_TESS_COORD), 232 ENUM(SYSTEM_VALUE_VERTICES_IN), 233 ENUM(SYSTEM_VALUE_PRIMITIVE_ID), 234 ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER), 235 ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER), 236 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID), 237 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX), 238 ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID), 239 ENUM(SYSTEM_VALUE_WORK_GROUP_ID), 240 ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS), 241 ENUM(SYSTEM_VALUE_LOCAL_GROUP_SIZE), 242 ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE), 243 ENUM(SYSTEM_VALUE_WORK_DIM), 244 ENUM(SYSTEM_VALUE_DEVICE_INDEX), 245 ENUM(SYSTEM_VALUE_VIEW_INDEX), 246 ENUM(SYSTEM_VALUE_VERTEX_CNT), 247 ENUM(SYSTEM_VALUE_VARYING_COORD), 248 }; 249 STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX); 250 return NAME(sysval); 251} 252 253const char * 254glsl_interp_mode_name(enum glsl_interp_mode qual) 255{ 256 static const char *names[] = { 257 ENUM(INTERP_MODE_NONE), 258 ENUM(INTERP_MODE_SMOOTH), 259 ENUM(INTERP_MODE_FLAT), 260 ENUM(INTERP_MODE_NOPERSPECTIVE), 261 }; 262 STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT); 263 return NAME(qual); 264} 265 266const char * 267gl_frag_result_name(gl_frag_result result) 268{ 269 static const char *names[] = { 270 ENUM(FRAG_RESULT_DEPTH), 271 ENUM(FRAG_RESULT_STENCIL), 272 ENUM(FRAG_RESULT_COLOR), 273 ENUM(FRAG_RESULT_SAMPLE_MASK), 274 ENUM(FRAG_RESULT_DATA0), 275 ENUM(FRAG_RESULT_DATA1), 276 ENUM(FRAG_RESULT_DATA2), 277 ENUM(FRAG_RESULT_DATA3), 278 ENUM(FRAG_RESULT_DATA4), 279 ENUM(FRAG_RESULT_DATA5), 280 ENUM(FRAG_RESULT_DATA6), 281 ENUM(FRAG_RESULT_DATA7), 282 }; 283 STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX); 284 return NAME(result); 285} 286