• 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 "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_glthread(struct gl_context *ctx, GLuint name,
102                                          bool glthread, const char *caller);
103 
104 extern struct gl_shader_program *
105 _mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name,
106                                 const char *caller);
107 
108 extern struct gl_shader_program *
109 _mesa_new_shader_program(GLuint name);
110 
111 extern struct gl_shader_program_data *
112 _mesa_create_shader_program_data(void);
113 
114 extern void
115 _mesa_clear_shader_program_data(struct gl_context *ctx,
116                                 struct gl_shader_program *shProg);
117 
118 extern void
119 _mesa_free_shader_program_data(struct gl_context *ctx,
120                                struct gl_shader_program *shProg);
121 
122 extern void
123 _mesa_delete_shader_program(struct gl_context *ctx,
124                             struct gl_shader_program *shProg);
125 
126 
127 extern void
128 _mesa_init_shader_object_functions(struct dd_function_table *driver);
129 
130 static inline gl_shader_stage
_mesa_shader_enum_to_shader_stage(GLenum v)131 _mesa_shader_enum_to_shader_stage(GLenum v)
132 {
133    switch (v) {
134    case GL_VERTEX_SHADER:
135       return MESA_SHADER_VERTEX;
136    case GL_FRAGMENT_SHADER:
137       return MESA_SHADER_FRAGMENT;
138    case GL_GEOMETRY_SHADER:
139       return MESA_SHADER_GEOMETRY;
140    case GL_TESS_CONTROL_SHADER:
141       return MESA_SHADER_TESS_CTRL;
142    case GL_TESS_EVALUATION_SHADER:
143       return MESA_SHADER_TESS_EVAL;
144    case GL_COMPUTE_SHADER:
145       return MESA_SHADER_COMPUTE;
146    default:
147       unreachable("bad value in _mesa_shader_enum_to_shader_stage()");
148    }
149 }
150 
151 /* 8 bytes + another underscore */
152 #define MESA_SUBROUTINE_PREFIX_LEN 9
153 static inline const char *
_mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage)154 _mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage)
155 {
156   switch (stage) {
157   case MESA_SHADER_VERTEX:
158     return "__subu_v";
159   case MESA_SHADER_GEOMETRY:
160     return "__subu_g";
161   case MESA_SHADER_FRAGMENT:
162     return "__subu_f";
163   case MESA_SHADER_COMPUTE:
164     return "__subu_c";
165   case MESA_SHADER_TESS_CTRL:
166     return "__subu_t";
167   case MESA_SHADER_TESS_EVAL:
168     return "__subu_e";
169   default:
170     return NULL;
171   }
172 }
173 
174 static inline gl_shader_stage
_mesa_shader_stage_from_subroutine_uniform(GLenum subuniform)175 _mesa_shader_stage_from_subroutine_uniform(GLenum subuniform)
176 {
177    switch (subuniform) {
178    case GL_VERTEX_SUBROUTINE_UNIFORM:
179       return MESA_SHADER_VERTEX;
180    case GL_GEOMETRY_SUBROUTINE_UNIFORM:
181       return MESA_SHADER_GEOMETRY;
182    case GL_FRAGMENT_SUBROUTINE_UNIFORM:
183       return MESA_SHADER_FRAGMENT;
184    case GL_COMPUTE_SUBROUTINE_UNIFORM:
185       return MESA_SHADER_COMPUTE;
186    case GL_TESS_CONTROL_SUBROUTINE_UNIFORM:
187       return MESA_SHADER_TESS_CTRL;
188    case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM:
189       return MESA_SHADER_TESS_EVAL;
190    }
191    unreachable("not reached");
192 }
193 
194 static inline gl_shader_stage
_mesa_shader_stage_from_subroutine(GLenum subroutine)195 _mesa_shader_stage_from_subroutine(GLenum subroutine)
196 {
197    switch (subroutine) {
198    case GL_VERTEX_SUBROUTINE:
199       return MESA_SHADER_VERTEX;
200    case GL_GEOMETRY_SUBROUTINE:
201       return MESA_SHADER_GEOMETRY;
202    case GL_FRAGMENT_SUBROUTINE:
203       return MESA_SHADER_FRAGMENT;
204    case GL_COMPUTE_SUBROUTINE:
205       return MESA_SHADER_COMPUTE;
206    case GL_TESS_CONTROL_SUBROUTINE:
207       return MESA_SHADER_TESS_CTRL;
208    case GL_TESS_EVALUATION_SUBROUTINE:
209       return MESA_SHADER_TESS_EVAL;
210    default:
211       unreachable("not reached");
212    }
213 }
214 
215 static inline GLenum
_mesa_shader_stage_to_subroutine(gl_shader_stage stage)216 _mesa_shader_stage_to_subroutine(gl_shader_stage stage)
217 {
218    switch (stage) {
219    case MESA_SHADER_VERTEX:
220       return GL_VERTEX_SUBROUTINE;
221    case MESA_SHADER_GEOMETRY:
222       return GL_GEOMETRY_SUBROUTINE;
223    case MESA_SHADER_FRAGMENT:
224       return GL_FRAGMENT_SUBROUTINE;
225    case MESA_SHADER_COMPUTE:
226       return GL_COMPUTE_SUBROUTINE;
227    case MESA_SHADER_TESS_CTRL:
228       return GL_TESS_CONTROL_SUBROUTINE;
229    case MESA_SHADER_TESS_EVAL:
230       return GL_TESS_EVALUATION_SUBROUTINE;
231    default:
232       unreachable("not reached");
233    }
234 }
235 
236 static inline GLenum
_mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)237 _mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)
238 {
239    switch (stage) {
240    case MESA_SHADER_VERTEX:
241       return GL_VERTEX_SUBROUTINE_UNIFORM;
242    case MESA_SHADER_GEOMETRY:
243       return GL_GEOMETRY_SUBROUTINE_UNIFORM;
244    case MESA_SHADER_FRAGMENT:
245       return GL_FRAGMENT_SUBROUTINE_UNIFORM;
246    case MESA_SHADER_COMPUTE:
247       return GL_COMPUTE_SUBROUTINE_UNIFORM;
248    case MESA_SHADER_TESS_CTRL:
249       return GL_TESS_CONTROL_SUBROUTINE_UNIFORM;
250    case MESA_SHADER_TESS_EVAL:
251       return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM;
252    default:
253       unreachable("not reached");
254    }
255 }
256 
257 extern bool
258 _mesa_validate_pipeline_io(struct gl_pipeline_object *);
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif /* SHADEROBJ_H */
265