d779d5a6dde3a9ed2d9da81bf5d323312635ee3b
[mesa.git] / src / mesa / state_tracker / st_program.h
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <keith@tungstengraphics.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_shader_tokens.h"
40
41
42 struct cso_fragment_shader;
43 struct cso_vertex_shader;
44
45
46 /**
47 * Derived from Mesa gl_fragment_program:
48 */
49 struct st_fragment_program
50 {
51 struct gl_fragment_program Base;
52 GLuint serialNo;
53
54 struct pipe_shader_state tgsi;
55 void *driver_shader;
56
57 /** Program prefixed with glBitmap prologue */
58 struct st_fragment_program *bitmap_program;
59 uint bitmap_sampler;
60 };
61
62
63
64 struct st_vp_varient_key
65 {
66 boolean passthrough_edgeflags;
67 };
68
69
70 /**
71 * This represents a vertex program, especially translated to match
72 * the inputs of a particular fragment shader.
73 */
74 struct st_vp_varient
75 {
76 /* Parameters which generated this translated version of a vertex
77 * shader:
78 */
79 struct st_vp_varient_key key;
80
81 /**
82 * TGSI tokens (to later generate a 'draw' module shader for
83 * selection/feedback/rasterpos)
84 */
85 struct pipe_shader_state tgsi;
86
87 /** Driver's compiled shader */
88 void *driver_shader;
89
90 /** For using our private draw module (glRasterPos) */
91 struct draw_vertex_shader *draw_shader;
92
93 /** Next in linked list */
94 struct st_vp_varient *next;
95
96 /** similar to that in st_vertex_program, but with information about edgeflags too */
97 GLuint num_inputs;
98 };
99
100
101 /**
102 * Derived from Mesa gl_fragment_program:
103 */
104 struct st_vertex_program
105 {
106 struct gl_vertex_program Base; /**< The Mesa vertex program */
107 GLuint serialNo, lastSerialNo;
108
109 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
110 GLuint input_to_index[VERT_ATTRIB_MAX];
111 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
112 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
113 GLuint num_inputs;
114
115 /** Maps VERT_RESULT_x to slot */
116 GLuint result_to_output[VERT_RESULT_MAX];
117 ubyte output_semantic_name[VERT_RESULT_MAX];
118 ubyte output_semantic_index[VERT_RESULT_MAX];
119 GLuint num_outputs;
120
121 /** List of translated varients of this vertex program.
122 */
123 struct st_vp_varient *varients;
124 };
125
126 /**
127 * Derived from Mesa gl_geometry_program:
128 */
129 struct st_geometry_program
130 {
131 struct gl_geometry_program Base; /**< The Mesa geometry program */
132 GLuint serialNo;
133
134 /** map GP input back to VP output */
135 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
136
137 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
138 GLuint input_to_index[GEOM_ATTRIB_MAX];
139 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
140 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
141
142 GLuint num_inputs;
143
144 GLuint input_to_slot[GEOM_ATTRIB_MAX]; /**< Maps GEOM_ATTRIB_x to slot */
145 GLuint num_input_slots;
146
147 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
148 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
149
150 struct pipe_shader_state tgsi;
151 void *driver_shader;
152 };
153
154 static INLINE struct st_fragment_program *
155 st_fragment_program( struct gl_fragment_program *fp )
156 {
157 return (struct st_fragment_program *)fp;
158 }
159
160
161 static INLINE struct st_vertex_program *
162 st_vertex_program( struct gl_vertex_program *vp )
163 {
164 return (struct st_vertex_program *)vp;
165 }
166
167 static INLINE struct st_geometry_program *
168 st_geometry_program( struct gl_geometry_program *vp )
169 {
170 return (struct st_geometry_program *)vp;
171 }
172
173 static INLINE void
174 st_reference_vertprog(struct st_context *st,
175 struct st_vertex_program **ptr,
176 struct st_vertex_program *prog)
177 {
178 _mesa_reference_program(st->ctx,
179 (struct gl_program **) ptr,
180 (struct gl_program *) prog);
181 }
182
183 static INLINE void
184 st_reference_geomprog(struct st_context *st,
185 struct st_geometry_program **ptr,
186 struct st_geometry_program *prog)
187 {
188 _mesa_reference_program(st->ctx,
189 (struct gl_program **) ptr,
190 (struct gl_program *) prog);
191 }
192
193 static INLINE void
194 st_reference_fragprog(struct st_context *st,
195 struct st_fragment_program **ptr,
196 struct st_fragment_program *prog)
197 {
198 _mesa_reference_program(st->ctx,
199 (struct gl_program **) ptr,
200 (struct gl_program *) prog);
201 }
202
203
204 extern void
205 st_translate_fragment_program(struct st_context *st,
206 struct st_fragment_program *fp);
207
208 extern void
209 st_translate_geometry_program(struct st_context *st,
210 struct st_geometry_program *stgp);
211
212 /* Called after program string change, discard all previous
213 * compilation results.
214 */
215 extern void
216 st_prepare_vertex_program(struct st_context *st,
217 struct st_vertex_program *stvp);
218
219 extern struct st_vp_varient *
220 st_translate_vertex_program(struct st_context *st,
221 struct st_vertex_program *stvp,
222 const struct st_vp_varient_key *key);
223
224 void
225 st_vp_release_varients( struct st_context *st,
226 struct st_vertex_program *stvp );
227
228 extern void
229 st_print_shaders(GLcontext *ctx);
230
231
232 #endif