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/glheader.h" 31#include "compiler/shader_enums.h" 32#include "program/ir_to_mesa.h" 33#include "util/macros.h" 34 35 36#ifdef __cplusplus 37extern "C" { 38#endif 39 40struct gl_shader_program_data; 41struct gl_linked_shader; 42struct dd_function_table; 43struct gl_pipeline_object; 44 45/** 46 * Internal functions 47 */ 48 49extern void 50_mesa_init_shader_state(struct gl_context * ctx); 51 52extern void 53_mesa_free_shader_state(struct gl_context *ctx); 54 55 56extern void 57_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, 58 struct gl_shader *sh); 59 60extern struct gl_shader * 61_mesa_lookup_shader(struct gl_context *ctx, GLuint name); 62 63extern struct gl_shader * 64_mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller); 65 66 67 68extern void 69_mesa_reference_shader_program_(struct gl_context *ctx, 70 struct gl_shader_program **ptr, 71 struct gl_shader_program *shProg); 72 73void 74_mesa_reference_shader_program_data(struct gl_context *ctx, 75 struct gl_shader_program_data **ptr, 76 struct gl_shader_program_data *data); 77 78static inline void 79_mesa_reference_shader_program(struct gl_context *ctx, 80 struct gl_shader_program **ptr, 81 struct gl_shader_program *shProg) 82{ 83 if (*ptr != shProg) 84 _mesa_reference_shader_program_(ctx, ptr, shProg); 85} 86 87extern struct gl_shader * 88_mesa_new_shader(GLuint name, gl_shader_stage type); 89 90extern void 91_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh); 92 93extern void 94_mesa_delete_linked_shader(struct gl_context *ctx, 95 struct gl_linked_shader *sh); 96 97extern struct gl_shader_program * 98_mesa_lookup_shader_program(struct gl_context *ctx, GLuint name); 99 100extern struct gl_shader_program * 101_mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name, 102 const char *caller); 103 104extern struct gl_shader_program * 105_mesa_new_shader_program(GLuint name); 106 107extern struct gl_shader_program_data * 108_mesa_create_shader_program_data(void); 109 110extern void 111_mesa_clear_shader_program_data(struct gl_context *ctx, 112 struct gl_shader_program *shProg); 113 114extern void 115_mesa_free_shader_program_data(struct gl_context *ctx, 116 struct gl_shader_program *shProg); 117 118extern void 119_mesa_delete_shader_program(struct gl_context *ctx, 120 struct gl_shader_program *shProg); 121 122 123extern void 124_mesa_init_shader_object_functions(struct dd_function_table *driver); 125 126static inline gl_shader_stage 127_mesa_shader_enum_to_shader_stage(GLenum v) 128{ 129 switch (v) { 130 case GL_VERTEX_SHADER: 131 return MESA_SHADER_VERTEX; 132 case GL_FRAGMENT_SHADER: 133 return MESA_SHADER_FRAGMENT; 134 case GL_GEOMETRY_SHADER: 135 return MESA_SHADER_GEOMETRY; 136 case GL_TESS_CONTROL_SHADER: 137 return MESA_SHADER_TESS_CTRL; 138 case GL_TESS_EVALUATION_SHADER: 139 return MESA_SHADER_TESS_EVAL; 140 case GL_COMPUTE_SHADER: 141 return MESA_SHADER_COMPUTE; 142 default: 143 unreachable("bad value in _mesa_shader_enum_to_shader_stage()"); 144 } 145} 146 147/* 8 bytes + another underscore */ 148#define MESA_SUBROUTINE_PREFIX_LEN 9 149static inline const char * 150_mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage) 151{ 152 switch (stage) { 153 case MESA_SHADER_VERTEX: 154 return "__subu_v"; 155 case MESA_SHADER_GEOMETRY: 156 return "__subu_g"; 157 case MESA_SHADER_FRAGMENT: 158 return "__subu_f"; 159 case MESA_SHADER_COMPUTE: 160 return "__subu_c"; 161 case MESA_SHADER_TESS_CTRL: 162 return "__subu_t"; 163 case MESA_SHADER_TESS_EVAL: 164 return "__subu_e"; 165 default: 166 return NULL; 167 } 168} 169 170static inline gl_shader_stage 171_mesa_shader_stage_from_subroutine_uniform(GLenum subuniform) 172{ 173 switch (subuniform) { 174 case GL_VERTEX_SUBROUTINE_UNIFORM: 175 return MESA_SHADER_VERTEX; 176 case GL_GEOMETRY_SUBROUTINE_UNIFORM: 177 return MESA_SHADER_GEOMETRY; 178 case GL_FRAGMENT_SUBROUTINE_UNIFORM: 179 return MESA_SHADER_FRAGMENT; 180 case GL_COMPUTE_SUBROUTINE_UNIFORM: 181 return MESA_SHADER_COMPUTE; 182 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM: 183 return MESA_SHADER_TESS_CTRL; 184 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM: 185 return MESA_SHADER_TESS_EVAL; 186 } 187 unreachable("not reached"); 188} 189 190static inline gl_shader_stage 191_mesa_shader_stage_from_subroutine(GLenum subroutine) 192{ 193 switch (subroutine) { 194 case GL_VERTEX_SUBROUTINE: 195 return MESA_SHADER_VERTEX; 196 case GL_GEOMETRY_SUBROUTINE: 197 return MESA_SHADER_GEOMETRY; 198 case GL_FRAGMENT_SUBROUTINE: 199 return MESA_SHADER_FRAGMENT; 200 case GL_COMPUTE_SUBROUTINE: 201 return MESA_SHADER_COMPUTE; 202 case GL_TESS_CONTROL_SUBROUTINE: 203 return MESA_SHADER_TESS_CTRL; 204 case GL_TESS_EVALUATION_SUBROUTINE: 205 return MESA_SHADER_TESS_EVAL; 206 } 207 unreachable("not reached"); 208} 209 210static inline GLenum 211_mesa_shader_stage_to_subroutine(gl_shader_stage stage) 212{ 213 switch (stage) { 214 case MESA_SHADER_VERTEX: 215 return GL_VERTEX_SUBROUTINE; 216 case MESA_SHADER_GEOMETRY: 217 return GL_GEOMETRY_SUBROUTINE; 218 case MESA_SHADER_FRAGMENT: 219 return GL_FRAGMENT_SUBROUTINE; 220 case MESA_SHADER_COMPUTE: 221 return GL_COMPUTE_SUBROUTINE; 222 case MESA_SHADER_TESS_CTRL: 223 return GL_TESS_CONTROL_SUBROUTINE; 224 case MESA_SHADER_TESS_EVAL: 225 return GL_TESS_EVALUATION_SUBROUTINE; 226 case MESA_SHADER_NONE: 227 break; 228 case MESA_SHADER_KERNEL: 229 unreachable("not reached"); 230 break; 231 } 232 unreachable("not reached"); 233} 234 235static inline GLenum 236_mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage) 237{ 238 switch (stage) { 239 case MESA_SHADER_VERTEX: 240 return GL_VERTEX_SUBROUTINE_UNIFORM; 241 case MESA_SHADER_GEOMETRY: 242 return GL_GEOMETRY_SUBROUTINE_UNIFORM; 243 case MESA_SHADER_FRAGMENT: 244 return GL_FRAGMENT_SUBROUTINE_UNIFORM; 245 case MESA_SHADER_COMPUTE: 246 return GL_COMPUTE_SUBROUTINE_UNIFORM; 247 case MESA_SHADER_TESS_CTRL: 248 return GL_TESS_CONTROL_SUBROUTINE_UNIFORM; 249 case MESA_SHADER_TESS_EVAL: 250 return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM; 251 case MESA_SHADER_NONE: 252 case MESA_SHADER_KERNEL: 253 break; 254 } 255 unreachable("not reached"); 256} 257 258extern bool 259_mesa_validate_pipeline_io(struct gl_pipeline_object *); 260 261#ifdef __cplusplus 262} 263#endif 264 265#endif /* SHADEROBJ_H */ 266