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