1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2004-2007 Brian Paul All Rights Reserved. 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 shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 26 #ifndef SHADEROBJ_H 27 #define SHADEROBJ_H 28 29 30 #include "main/compiler.h" 31 #include "main/glheader.h" 32 #include "main/mtypes.h" 33 #include "program/ir_to_mesa.h" 34 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 41 /** 42 * Internal functions 43 */ 44 45 extern void 46 _mesa_init_shader_state(struct gl_context * ctx); 47 48 extern void 49 _mesa_free_shader_state(struct gl_context *ctx); 50 51 52 extern void 53 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, 54 struct gl_shader *sh); 55 56 extern struct gl_shader * 57 _mesa_lookup_shader(struct gl_context *ctx, GLuint name); 58 59 extern struct gl_shader * 60 _mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller); 61 62 63 64 extern void 65 _mesa_reference_shader_program_(struct gl_context *ctx, 66 struct gl_shader_program **ptr, 67 struct gl_shader_program *shProg); 68 69 void 70 _mesa_reference_shader_program_data(struct gl_context *ctx, 71 struct gl_shader_program_data **ptr, 72 struct gl_shader_program_data *data); 73 74 static inline void 75 _mesa_reference_shader_program(struct gl_context *ctx, 76 struct gl_shader_program **ptr, 77 struct gl_shader_program *shProg) 78 { 79 if (*ptr != shProg) 80 _mesa_reference_shader_program_(ctx, ptr, shProg); 81 } 82 83 extern struct gl_shader * 84 _mesa_new_shader(GLuint name, gl_shader_stage type); 85 86 extern void 87 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh); 88 89 extern void 90 _mesa_delete_linked_shader(struct gl_context *ctx, 91 struct gl_linked_shader *sh); 92 93 extern struct gl_shader_program * 94 _mesa_lookup_shader_program(struct gl_context *ctx, GLuint name); 95 96 extern struct gl_shader_program * 97 _mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name, 98 const char *caller); 99 100 extern struct gl_shader_program * 101 _mesa_new_shader_program(GLuint name); 102 103 extern void 104 _mesa_clear_shader_program_data(struct gl_context *ctx, 105 struct gl_shader_program *shProg); 106 107 extern void 108 _mesa_free_shader_program_data(struct gl_context *ctx, 109 struct gl_shader_program *shProg); 110 111 extern void 112 _mesa_delete_shader_program(struct gl_context *ctx, 113 struct gl_shader_program *shProg); 114 115 116 extern void 117 _mesa_init_shader_object_functions(struct dd_function_table *driver); 118 119 static inline gl_shader_stage 120 _mesa_shader_enum_to_shader_stage(GLenum v) 121 { 122 switch (v) { 123 case GL_VERTEX_SHADER: 124 return MESA_SHADER_VERTEX; 125 case GL_FRAGMENT_SHADER: 126 return MESA_SHADER_FRAGMENT; 127 case GL_GEOMETRY_SHADER: 128 return MESA_SHADER_GEOMETRY; 129 case GL_TESS_CONTROL_SHADER: 130 return MESA_SHADER_TESS_CTRL; 131 case GL_TESS_EVALUATION_SHADER: 132 return MESA_SHADER_TESS_EVAL; 133 case GL_COMPUTE_SHADER: 134 return MESA_SHADER_COMPUTE; 135 default: 136 unreachable("bad value in _mesa_shader_enum_to_shader_stage()"); 137 } 138 } 139 140 /* 8 bytes + another underscore */ 141 #define MESA_SUBROUTINE_PREFIX_LEN 9 142 static inline const char * 143 _mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage) 144 { 145 switch (stage) { 146 case MESA_SHADER_VERTEX: 147 return "__subu_v"; 148 case MESA_SHADER_GEOMETRY: 149 return "__subu_g"; 150 case MESA_SHADER_FRAGMENT: 151 return "__subu_f"; 152 case MESA_SHADER_COMPUTE: 153 return "__subu_c"; 154 case MESA_SHADER_TESS_CTRL: 155 return "__subu_t"; 156 case MESA_SHADER_TESS_EVAL: 157 return "__subu_e"; 158 default: 159 return NULL; 160 } 161 } 162 163 static inline gl_shader_stage 164 _mesa_shader_stage_from_subroutine_uniform(GLenum subuniform) 165 { 166 switch (subuniform) { 167 case GL_VERTEX_SUBROUTINE_UNIFORM: 168 return MESA_SHADER_VERTEX; 169 case GL_GEOMETRY_SUBROUTINE_UNIFORM: 170 return MESA_SHADER_GEOMETRY; 171 case GL_FRAGMENT_SUBROUTINE_UNIFORM: 172 return MESA_SHADER_FRAGMENT; 173 case GL_COMPUTE_SUBROUTINE_UNIFORM: 174 return MESA_SHADER_COMPUTE; 175 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM: 176 return MESA_SHADER_TESS_CTRL; 177 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM: 178 return MESA_SHADER_TESS_EVAL; 179 } 180 unreachable("not reached"); 181 } 182 183 static inline gl_shader_stage 184 _mesa_shader_stage_from_subroutine(GLenum subroutine) 185 { 186 switch (subroutine) { 187 case GL_VERTEX_SUBROUTINE: 188 return MESA_SHADER_VERTEX; 189 case GL_GEOMETRY_SUBROUTINE: 190 return MESA_SHADER_GEOMETRY; 191 case GL_FRAGMENT_SUBROUTINE: 192 return MESA_SHADER_FRAGMENT; 193 case GL_COMPUTE_SUBROUTINE: 194 return MESA_SHADER_COMPUTE; 195 case GL_TESS_CONTROL_SUBROUTINE: 196 return MESA_SHADER_TESS_CTRL; 197 case GL_TESS_EVALUATION_SUBROUTINE: 198 return MESA_SHADER_TESS_EVAL; 199 } 200 unreachable("not reached"); 201 } 202 203 static inline GLenum 204 _mesa_shader_stage_to_subroutine(gl_shader_stage stage) 205 { 206 switch (stage) { 207 case MESA_SHADER_VERTEX: 208 return GL_VERTEX_SUBROUTINE; 209 case MESA_SHADER_GEOMETRY: 210 return GL_GEOMETRY_SUBROUTINE; 211 case MESA_SHADER_FRAGMENT: 212 return GL_FRAGMENT_SUBROUTINE; 213 case MESA_SHADER_COMPUTE: 214 return GL_COMPUTE_SUBROUTINE; 215 case MESA_SHADER_TESS_CTRL: 216 return GL_TESS_CONTROL_SUBROUTINE; 217 case MESA_SHADER_TESS_EVAL: 218 return GL_TESS_EVALUATION_SUBROUTINE; 219 } 220 unreachable("not reached"); 221 } 222 223 static inline GLenum 224 _mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage) 225 { 226 switch (stage) { 227 case MESA_SHADER_VERTEX: 228 return GL_VERTEX_SUBROUTINE_UNIFORM; 229 case MESA_SHADER_GEOMETRY: 230 return GL_GEOMETRY_SUBROUTINE_UNIFORM; 231 case MESA_SHADER_FRAGMENT: 232 return GL_FRAGMENT_SUBROUTINE_UNIFORM; 233 case MESA_SHADER_COMPUTE: 234 return GL_COMPUTE_SUBROUTINE_UNIFORM; 235 case MESA_SHADER_TESS_CTRL: 236 return GL_TESS_CONTROL_SUBROUTINE_UNIFORM; 237 case MESA_SHADER_TESS_EVAL: 238 return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM; 239 } 240 unreachable("not reached"); 241 } 242 243 extern bool 244 _mesa_validate_pipeline_io(struct gl_pipeline_object *); 245 246 #ifdef __cplusplus 247 } 248 #endif 249 250 #endif /* SHADEROBJ_H */ 251