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