1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 2004-2007 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg 26848b8605Smrg#ifndef SHADEROBJ_H 27848b8605Smrg#define SHADEROBJ_H 28848b8605Smrg 29848b8605Smrg 30848b8605Smrg#include "main/glheader.h" 31b8e80941Smrg#include "compiler/shader_enums.h" 32848b8605Smrg#include "program/ir_to_mesa.h" 33b8e80941Smrg#include "util/macros.h" 34848b8605Smrg 35848b8605Smrg 36848b8605Smrg#ifdef __cplusplus 37848b8605Smrgextern "C" { 38848b8605Smrg#endif 39848b8605Smrg 40b8e80941Smrgstruct gl_shader_program_data; 41b8e80941Smrgstruct gl_linked_shader; 42b8e80941Smrgstruct dd_function_table; 43b8e80941Smrgstruct gl_pipeline_object; 44848b8605Smrg 45848b8605Smrg/** 46848b8605Smrg * Internal functions 47848b8605Smrg */ 48848b8605Smrg 49848b8605Smrgextern void 50848b8605Smrg_mesa_init_shader_state(struct gl_context * ctx); 51848b8605Smrg 52848b8605Smrgextern void 53848b8605Smrg_mesa_free_shader_state(struct gl_context *ctx); 54848b8605Smrg 55848b8605Smrg 56848b8605Smrgextern void 57848b8605Smrg_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, 58848b8605Smrg struct gl_shader *sh); 59848b8605Smrg 60848b8605Smrgextern struct gl_shader * 61848b8605Smrg_mesa_lookup_shader(struct gl_context *ctx, GLuint name); 62848b8605Smrg 63848b8605Smrgextern struct gl_shader * 64848b8605Smrg_mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller); 65848b8605Smrg 66848b8605Smrg 67848b8605Smrg 68848b8605Smrgextern void 69b8e80941Smrg_mesa_reference_shader_program_(struct gl_context *ctx, 70848b8605Smrg struct gl_shader_program **ptr, 71848b8605Smrg struct gl_shader_program *shProg); 72b8e80941Smrg 73b8e80941Smrgvoid 74b8e80941Smrg_mesa_reference_shader_program_data(struct gl_context *ctx, 75b8e80941Smrg struct gl_shader_program_data **ptr, 76b8e80941Smrg struct gl_shader_program_data *data); 77b8e80941Smrg 78b8e80941Smrgstatic inline void 79b8e80941Smrg_mesa_reference_shader_program(struct gl_context *ctx, 80b8e80941Smrg struct gl_shader_program **ptr, 81b8e80941Smrg struct gl_shader_program *shProg) 82b8e80941Smrg{ 83b8e80941Smrg if (*ptr != shProg) 84b8e80941Smrg _mesa_reference_shader_program_(ctx, ptr, shProg); 85b8e80941Smrg} 86848b8605Smrg 87848b8605Smrgextern struct gl_shader * 88b8e80941Smrg_mesa_new_shader(GLuint name, gl_shader_stage type); 89b8e80941Smrg 90b8e80941Smrgextern void 91b8e80941Smrg_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh); 92848b8605Smrg 93848b8605Smrgextern void 94b8e80941Smrg_mesa_delete_linked_shader(struct gl_context *ctx, 95b8e80941Smrg struct gl_linked_shader *sh); 96848b8605Smrg 97848b8605Smrgextern struct gl_shader_program * 98848b8605Smrg_mesa_lookup_shader_program(struct gl_context *ctx, GLuint name); 99848b8605Smrg 100848b8605Smrgextern struct gl_shader_program * 101848b8605Smrg_mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name, 102848b8605Smrg const char *caller); 103848b8605Smrg 104b8e80941Smrgextern struct gl_shader_program * 105b8e80941Smrg_mesa_new_shader_program(GLuint name); 106b8e80941Smrg 107b8e80941Smrgextern struct gl_shader_program_data * 108b8e80941Smrg_mesa_create_shader_program_data(void); 109b8e80941Smrg 110848b8605Smrgextern void 111848b8605Smrg_mesa_clear_shader_program_data(struct gl_context *ctx, 112848b8605Smrg struct gl_shader_program *shProg); 113848b8605Smrg 114848b8605Smrgextern void 115848b8605Smrg_mesa_free_shader_program_data(struct gl_context *ctx, 116848b8605Smrg struct gl_shader_program *shProg); 117848b8605Smrg 118848b8605Smrgextern void 119b8e80941Smrg_mesa_delete_shader_program(struct gl_context *ctx, 120b8e80941Smrg struct gl_shader_program *shProg); 121848b8605Smrg 122848b8605Smrg 123848b8605Smrgextern void 124b8e80941Smrg_mesa_init_shader_object_functions(struct dd_function_table *driver); 125848b8605Smrg 126848b8605Smrgstatic inline gl_shader_stage 127848b8605Smrg_mesa_shader_enum_to_shader_stage(GLenum v) 128848b8605Smrg{ 129848b8605Smrg switch (v) { 130848b8605Smrg case GL_VERTEX_SHADER: 131848b8605Smrg return MESA_SHADER_VERTEX; 132848b8605Smrg case GL_FRAGMENT_SHADER: 133848b8605Smrg return MESA_SHADER_FRAGMENT; 134848b8605Smrg case GL_GEOMETRY_SHADER: 135848b8605Smrg return MESA_SHADER_GEOMETRY; 136b8e80941Smrg case GL_TESS_CONTROL_SHADER: 137b8e80941Smrg return MESA_SHADER_TESS_CTRL; 138b8e80941Smrg case GL_TESS_EVALUATION_SHADER: 139b8e80941Smrg return MESA_SHADER_TESS_EVAL; 140848b8605Smrg case GL_COMPUTE_SHADER: 141848b8605Smrg return MESA_SHADER_COMPUTE; 142848b8605Smrg default: 143b8e80941Smrg unreachable("bad value in _mesa_shader_enum_to_shader_stage()"); 144b8e80941Smrg } 145b8e80941Smrg} 146b8e80941Smrg 147b8e80941Smrg/* 8 bytes + another underscore */ 148b8e80941Smrg#define MESA_SUBROUTINE_PREFIX_LEN 9 149b8e80941Smrgstatic inline const char * 150b8e80941Smrg_mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage) 151b8e80941Smrg{ 152b8e80941Smrg switch (stage) { 153b8e80941Smrg case MESA_SHADER_VERTEX: 154b8e80941Smrg return "__subu_v"; 155b8e80941Smrg case MESA_SHADER_GEOMETRY: 156b8e80941Smrg return "__subu_g"; 157b8e80941Smrg case MESA_SHADER_FRAGMENT: 158b8e80941Smrg return "__subu_f"; 159b8e80941Smrg case MESA_SHADER_COMPUTE: 160b8e80941Smrg return "__subu_c"; 161b8e80941Smrg case MESA_SHADER_TESS_CTRL: 162b8e80941Smrg return "__subu_t"; 163b8e80941Smrg case MESA_SHADER_TESS_EVAL: 164b8e80941Smrg return "__subu_e"; 165b8e80941Smrg default: 166b8e80941Smrg return NULL; 167b8e80941Smrg } 168b8e80941Smrg} 169b8e80941Smrg 170b8e80941Smrgstatic inline gl_shader_stage 171b8e80941Smrg_mesa_shader_stage_from_subroutine_uniform(GLenum subuniform) 172b8e80941Smrg{ 173b8e80941Smrg switch (subuniform) { 174b8e80941Smrg case GL_VERTEX_SUBROUTINE_UNIFORM: 175b8e80941Smrg return MESA_SHADER_VERTEX; 176b8e80941Smrg case GL_GEOMETRY_SUBROUTINE_UNIFORM: 177b8e80941Smrg return MESA_SHADER_GEOMETRY; 178b8e80941Smrg case GL_FRAGMENT_SUBROUTINE_UNIFORM: 179b8e80941Smrg return MESA_SHADER_FRAGMENT; 180b8e80941Smrg case GL_COMPUTE_SUBROUTINE_UNIFORM: 181b8e80941Smrg return MESA_SHADER_COMPUTE; 182b8e80941Smrg case GL_TESS_CONTROL_SUBROUTINE_UNIFORM: 183b8e80941Smrg return MESA_SHADER_TESS_CTRL; 184b8e80941Smrg case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM: 185b8e80941Smrg return MESA_SHADER_TESS_EVAL; 186b8e80941Smrg } 187b8e80941Smrg unreachable("not reached"); 188b8e80941Smrg} 189b8e80941Smrg 190b8e80941Smrgstatic inline gl_shader_stage 191b8e80941Smrg_mesa_shader_stage_from_subroutine(GLenum subroutine) 192b8e80941Smrg{ 193b8e80941Smrg switch (subroutine) { 194b8e80941Smrg case GL_VERTEX_SUBROUTINE: 195848b8605Smrg return MESA_SHADER_VERTEX; 196b8e80941Smrg case GL_GEOMETRY_SUBROUTINE: 197b8e80941Smrg return MESA_SHADER_GEOMETRY; 198b8e80941Smrg case GL_FRAGMENT_SUBROUTINE: 199b8e80941Smrg return MESA_SHADER_FRAGMENT; 200b8e80941Smrg case GL_COMPUTE_SUBROUTINE: 201b8e80941Smrg return MESA_SHADER_COMPUTE; 202b8e80941Smrg case GL_TESS_CONTROL_SUBROUTINE: 203b8e80941Smrg return MESA_SHADER_TESS_CTRL; 204b8e80941Smrg case GL_TESS_EVALUATION_SUBROUTINE: 205b8e80941Smrg return MESA_SHADER_TESS_EVAL; 206b8e80941Smrg } 207b8e80941Smrg unreachable("not reached"); 208b8e80941Smrg} 209b8e80941Smrg 210b8e80941Smrgstatic inline GLenum 211b8e80941Smrg_mesa_shader_stage_to_subroutine(gl_shader_stage stage) 212b8e80941Smrg{ 213b8e80941Smrg switch (stage) { 214b8e80941Smrg case MESA_SHADER_VERTEX: 215b8e80941Smrg return GL_VERTEX_SUBROUTINE; 216b8e80941Smrg case MESA_SHADER_GEOMETRY: 217b8e80941Smrg return GL_GEOMETRY_SUBROUTINE; 218b8e80941Smrg case MESA_SHADER_FRAGMENT: 219b8e80941Smrg return GL_FRAGMENT_SUBROUTINE; 220b8e80941Smrg case MESA_SHADER_COMPUTE: 221b8e80941Smrg return GL_COMPUTE_SUBROUTINE; 222b8e80941Smrg case MESA_SHADER_TESS_CTRL: 223b8e80941Smrg return GL_TESS_CONTROL_SUBROUTINE; 224b8e80941Smrg case MESA_SHADER_TESS_EVAL: 225b8e80941Smrg return GL_TESS_EVALUATION_SUBROUTINE; 226b8e80941Smrg case MESA_SHADER_NONE: 227b8e80941Smrg break; 228b8e80941Smrg case MESA_SHADER_KERNEL: 229b8e80941Smrg unreachable("not reached"); 230b8e80941Smrg break; 231b8e80941Smrg } 232b8e80941Smrg unreachable("not reached"); 233b8e80941Smrg} 234b8e80941Smrg 235b8e80941Smrgstatic inline GLenum 236b8e80941Smrg_mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage) 237b8e80941Smrg{ 238b8e80941Smrg switch (stage) { 239b8e80941Smrg case MESA_SHADER_VERTEX: 240b8e80941Smrg return GL_VERTEX_SUBROUTINE_UNIFORM; 241b8e80941Smrg case MESA_SHADER_GEOMETRY: 242b8e80941Smrg return GL_GEOMETRY_SUBROUTINE_UNIFORM; 243b8e80941Smrg case MESA_SHADER_FRAGMENT: 244b8e80941Smrg return GL_FRAGMENT_SUBROUTINE_UNIFORM; 245b8e80941Smrg case MESA_SHADER_COMPUTE: 246b8e80941Smrg return GL_COMPUTE_SUBROUTINE_UNIFORM; 247b8e80941Smrg case MESA_SHADER_TESS_CTRL: 248b8e80941Smrg return GL_TESS_CONTROL_SUBROUTINE_UNIFORM; 249b8e80941Smrg case MESA_SHADER_TESS_EVAL: 250b8e80941Smrg return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM; 251b8e80941Smrg case MESA_SHADER_NONE: 252b8e80941Smrg case MESA_SHADER_KERNEL: 253b8e80941Smrg break; 254848b8605Smrg } 255b8e80941Smrg unreachable("not reached"); 256848b8605Smrg} 257848b8605Smrg 258b8e80941Smrgextern bool 259b8e80941Smrg_mesa_validate_pipeline_io(struct gl_pipeline_object *); 260848b8605Smrg 261848b8605Smrg#ifdef __cplusplus 262848b8605Smrg} 263848b8605Smrg#endif 264848b8605Smrg 265848b8605Smrg#endif /* SHADEROBJ_H */ 266