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
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_context *ctx,
75 struct gl_shader_program_data **ptr,
76 struct gl_shader_program_data *data);
77
78 static inline void
_mesa_reference_shader_program(struct gl_context * ctx,struct gl_shader_program ** ptr,struct gl_shader_program * shProg)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
87 extern struct gl_shader *
88 _mesa_new_shader(GLuint name, gl_shader_stage type);
89
90 extern void
91 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh);
92
93 extern void
94 _mesa_delete_linked_shader(struct gl_context *ctx,
95 struct gl_linked_shader *sh);
96
97 extern struct gl_shader_program *
98 _mesa_lookup_shader_program(struct gl_context *ctx, GLuint name);
99
100 extern struct gl_shader_program *
101 _mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name,
102 const char *caller);
103
104 extern struct gl_shader_program *
105 _mesa_new_shader_program(GLuint name);
106
107 extern struct gl_shader_program_data *
108 _mesa_create_shader_program_data(void);
109
110 extern void
111 _mesa_clear_shader_program_data(struct gl_context *ctx,
112 struct gl_shader_program *shProg);
113
114 extern void
115 _mesa_free_shader_program_data(struct gl_context *ctx,
116 struct gl_shader_program *shProg);
117
118 extern void
119 _mesa_delete_shader_program(struct gl_context *ctx,
120 struct gl_shader_program *shProg);
121
122
123 extern void
124 _mesa_init_shader_object_functions(struct dd_function_table *driver);
125
126 static inline gl_shader_stage
_mesa_shader_enum_to_shader_stage(GLenum v)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
149 static inline const char *
_mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage)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
170 static inline gl_shader_stage
_mesa_shader_stage_from_subroutine_uniform(GLenum subuniform)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
190 static inline gl_shader_stage
_mesa_shader_stage_from_subroutine(GLenum subroutine)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 default:
207 unreachable("not reached");
208 }
209 }
210
211 static inline GLenum
_mesa_shader_stage_to_subroutine(gl_shader_stage stage)212 _mesa_shader_stage_to_subroutine(gl_shader_stage stage)
213 {
214 switch (stage) {
215 case MESA_SHADER_VERTEX:
216 return GL_VERTEX_SUBROUTINE;
217 case MESA_SHADER_GEOMETRY:
218 return GL_GEOMETRY_SUBROUTINE;
219 case MESA_SHADER_FRAGMENT:
220 return GL_FRAGMENT_SUBROUTINE;
221 case MESA_SHADER_COMPUTE:
222 return GL_COMPUTE_SUBROUTINE;
223 case MESA_SHADER_TESS_CTRL:
224 return GL_TESS_CONTROL_SUBROUTINE;
225 case MESA_SHADER_TESS_EVAL:
226 return GL_TESS_EVALUATION_SUBROUTINE;
227 default:
228 unreachable("not reached");
229 }
230 }
231
232 static inline GLenum
_mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)233 _mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)
234 {
235 switch (stage) {
236 case MESA_SHADER_VERTEX:
237 return GL_VERTEX_SUBROUTINE_UNIFORM;
238 case MESA_SHADER_GEOMETRY:
239 return GL_GEOMETRY_SUBROUTINE_UNIFORM;
240 case MESA_SHADER_FRAGMENT:
241 return GL_FRAGMENT_SUBROUTINE_UNIFORM;
242 case MESA_SHADER_COMPUTE:
243 return GL_COMPUTE_SUBROUTINE_UNIFORM;
244 case MESA_SHADER_TESS_CTRL:
245 return GL_TESS_CONTROL_SUBROUTINE_UNIFORM;
246 case MESA_SHADER_TESS_EVAL:
247 return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM;
248 default:
249 unreachable("not reached");
250 }
251 }
252
253 extern bool
254 _mesa_validate_pipeline_io(struct gl_pipeline_object *);
255
256 #ifdef __cplusplus
257 }
258 #endif
259
260 #endif /* SHADEROBJ_H */
261