r600g: Implement GL_ARB_texture_gather
[mesa.git] / src / mesa / state_tracker / st_program.h
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keithw@vmware.com>
31 */
32
33
34 #ifndef ST_PROGRAM_H
35 #define ST_PROGRAM_H
36
37 #include "main/mtypes.h"
38 #include "program/program.h"
39 #include "pipe/p_state.h"
40 #include "st_context.h"
41 #include "st_glsl_to_tgsi.h"
42
43
44 /** Fragment program variant key */
45 struct st_fp_variant_key
46 {
47 struct st_context *st; /**< variants are per-context */
48
49 /** for glBitmap */
50 GLuint bitmap:1; /**< glBitmap variant? */
51
52 /** for glDrawPixels */
53 GLuint drawpixels:1; /**< glDrawPixels variant */
54 GLuint scaleAndBias:1; /**< glDrawPixels w/ scale and/or bias? */
55 GLuint pixelMaps:1; /**< glDrawPixels w/ pixel lookup map? */
56 GLuint drawpixels_z:1; /**< glDrawPixels(GL_DEPTH) */
57 GLuint drawpixels_stencil:1; /**< glDrawPixels(GL_STENCIL) */
58
59 /** for ARB_color_buffer_float */
60 GLuint clamp_color:1;
61
62 /** for ARB_sample_shading */
63 GLuint persample_shading:1;
64 };
65
66
67 /**
68 * Variant of a fragment program.
69 */
70 struct st_fp_variant
71 {
72 /** Parameters which generated this version of fragment program */
73 struct st_fp_variant_key key;
74
75 struct pipe_shader_state tgsi;
76
77 /** Driver's compiled shader */
78 void *driver_shader;
79
80 /** For glBitmap variants */
81 struct gl_program_parameter_list *parameters;
82 uint bitmap_sampler;
83
84 /** next in linked list */
85 struct st_fp_variant *next;
86 };
87
88
89 /**
90 * Derived from Mesa gl_fragment_program:
91 */
92 struct st_fragment_program
93 {
94 struct gl_fragment_program Base;
95 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
96
97 struct st_fp_variant *variants;
98 };
99
100
101
102 /** Vertex program variant key */
103 struct st_vp_variant_key
104 {
105 struct st_context *st; /**< variants are per-context */
106 boolean passthrough_edgeflags;
107
108 /** for ARB_color_buffer_float */
109 boolean clamp_color;
110 };
111
112
113 /**
114 * This represents a vertex program, especially translated to match
115 * the inputs of a particular fragment shader.
116 */
117 struct st_vp_variant
118 {
119 /* Parameters which generated this translated version of a vertex
120 * shader:
121 */
122 struct st_vp_variant_key key;
123
124 /**
125 * TGSI tokens (to later generate a 'draw' module shader for
126 * selection/feedback/rasterpos)
127 */
128 struct pipe_shader_state tgsi;
129
130 /** Driver's compiled shader */
131 void *driver_shader;
132
133 /** For using our private draw module (glRasterPos) */
134 struct draw_vertex_shader *draw_shader;
135
136 /** Next in linked list */
137 struct st_vp_variant *next;
138
139 /** similar to that in st_vertex_program, but with edgeflags info too */
140 GLuint num_inputs;
141 };
142
143
144 /**
145 * Derived from Mesa gl_fragment_program:
146 */
147 struct st_vertex_program
148 {
149 struct gl_vertex_program Base; /**< The Mesa vertex program */
150 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
151
152 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
153 GLuint input_to_index[VERT_ATTRIB_MAX];
154 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
155 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
156 GLuint num_inputs;
157
158 /** Maps VARYING_SLOT_x to slot */
159 GLuint result_to_output[VARYING_SLOT_MAX];
160 ubyte output_semantic_name[VARYING_SLOT_MAX];
161 ubyte output_semantic_index[VARYING_SLOT_MAX];
162 GLuint num_outputs;
163
164 /** List of translated variants of this vertex program.
165 */
166 struct st_vp_variant *variants;
167 };
168
169
170
171 /** Geometry program variant key */
172 struct st_gp_variant_key
173 {
174 struct st_context *st; /**< variants are per-context */
175 /* no other fields yet */
176 };
177
178
179 /**
180 * Geometry program variant.
181 */
182 struct st_gp_variant
183 {
184 /* Parameters which generated this translated version of a vertex */
185 struct st_gp_variant_key key;
186
187 void *driver_shader;
188
189 struct st_gp_variant *next;
190 };
191
192
193 /**
194 * Derived from Mesa gl_geometry_program:
195 */
196 struct st_geometry_program
197 {
198 struct gl_geometry_program Base; /**< The Mesa geometry program */
199 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
200
201 /** map GP input back to VP output */
202 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
203
204 /** maps a Mesa VARYING_SLOT_x to a packed TGSI input index */
205 GLuint input_to_index[VARYING_SLOT_MAX];
206 /** maps a TGSI input index back to a Mesa VARYING_SLOT_x */
207 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
208
209 GLuint num_inputs;
210
211 GLuint input_to_slot[VARYING_SLOT_MAX]; /**< Maps VARYING_SLOT_x to slot */
212 GLuint num_input_slots;
213
214 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
215 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
216
217 struct pipe_shader_state tgsi;
218
219 struct st_gp_variant *variants;
220 };
221
222
223
224 static INLINE struct st_fragment_program *
225 st_fragment_program( struct gl_fragment_program *fp )
226 {
227 return (struct st_fragment_program *)fp;
228 }
229
230
231 static INLINE struct st_vertex_program *
232 st_vertex_program( struct gl_vertex_program *vp )
233 {
234 return (struct st_vertex_program *)vp;
235 }
236
237 static INLINE struct st_geometry_program *
238 st_geometry_program( struct gl_geometry_program *gp )
239 {
240 return (struct st_geometry_program *)gp;
241 }
242
243 static INLINE void
244 st_reference_vertprog(struct st_context *st,
245 struct st_vertex_program **ptr,
246 struct st_vertex_program *prog)
247 {
248 _mesa_reference_program(st->ctx,
249 (struct gl_program **) ptr,
250 (struct gl_program *) prog);
251 }
252
253 static INLINE void
254 st_reference_geomprog(struct st_context *st,
255 struct st_geometry_program **ptr,
256 struct st_geometry_program *prog)
257 {
258 _mesa_reference_program(st->ctx,
259 (struct gl_program **) ptr,
260 (struct gl_program *) prog);
261 }
262
263 static INLINE void
264 st_reference_fragprog(struct st_context *st,
265 struct st_fragment_program **ptr,
266 struct st_fragment_program *prog)
267 {
268 _mesa_reference_program(st->ctx,
269 (struct gl_program **) ptr,
270 (struct gl_program *) prog);
271 }
272
273
274 extern struct st_vp_variant *
275 st_get_vp_variant(struct st_context *st,
276 struct st_vertex_program *stvp,
277 const struct st_vp_variant_key *key);
278
279
280 extern struct st_fp_variant *
281 st_get_fp_variant(struct st_context *st,
282 struct st_fragment_program *stfp,
283 const struct st_fp_variant_key *key);
284
285
286 extern struct st_gp_variant *
287 st_get_gp_variant(struct st_context *st,
288 struct st_geometry_program *stgp,
289 const struct st_gp_variant_key *key);
290
291
292 extern void
293 st_prepare_vertex_program(struct gl_context *ctx,
294 struct st_vertex_program *stvp);
295
296 extern GLboolean
297 st_prepare_fragment_program(struct gl_context *ctx,
298 struct st_fragment_program *stfp);
299
300
301 extern void
302 st_release_vp_variants( struct st_context *st,
303 struct st_vertex_program *stvp );
304
305 extern void
306 st_release_fp_variants( struct st_context *st,
307 struct st_fragment_program *stfp );
308
309 extern void
310 st_release_gp_variants(struct st_context *st,
311 struct st_geometry_program *stgp);
312
313
314 extern void
315 st_print_shaders(struct gl_context *ctx);
316
317 extern void
318 st_destroy_program_variants(struct st_context *st);
319
320
321 extern void
322 st_print_current_vertex_program(void);
323
324
325 #endif