6b9a9226df583b0de95b340d1ab59a5dacafd384
[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 "shader/program.h"
39 #include "pipe/p_shader_tokens.h"
40
41
42 struct cso_fragment_shader;
43 struct cso_vertex_shader;
44 struct translated_vertex_program;
45
46
47 /**
48 * Derived from Mesa gl_fragment_program:
49 */
50 struct st_fragment_program
51 {
52 struct gl_fragment_program Base;
53 GLuint serialNo;
54
55 GLuint input_to_slot[FRAG_ATTRIB_MAX]; /**< Maps FRAG_ATTRIB_x to slot */
56 GLuint num_input_slots;
57
58 /** map FP input back to VP output */
59 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
60
61 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
62 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
63
64 struct pipe_shader_state state;
65 void *driver_shader;
66
67 /** Program prefixed with glBitmap prologue */
68 struct st_fragment_program *bitmap_program;
69 uint bitmap_sampler;
70 };
71
72
73
74 struct st_vp_varient_key
75 {
76 boolean passthrough_edgeflags;
77 };
78
79
80 /**
81 * This represents a vertex program, especially translated to match
82 * the inputs of a particular fragment shader.
83 */
84 struct st_vp_varient
85 {
86 /* Parameters which generated this translated version of a vertex
87 * shader:
88 */
89 struct st_vp_varient_key key;
90
91 /** TGSI tokens -- why?
92 */
93 struct pipe_shader_state state;
94
95 /** Driver's compiled shader */
96 void *driver_shader;
97
98 /** For using our private draw module (glRasterPos) */
99 struct draw_vertex_shader *draw_shader;
100
101 /** Next in linked list */
102 struct st_vp_varient *next;
103
104 /** similar to that in st_vertex_program, but with information about edgeflags too */
105 GLuint num_inputs;
106 };
107
108
109
110
111 /**
112 * Derived from Mesa gl_fragment_program:
113 */
114 struct st_vertex_program
115 {
116 struct gl_vertex_program Base; /**< The Mesa vertex program */
117 GLuint serialNo, lastSerialNo;
118
119 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
120 GLuint input_to_index[VERT_ATTRIB_MAX];
121 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
122 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
123 GLuint num_inputs;
124
125 /** Maps VERT_RESULT_x to slot */
126 GLuint result_to_output[VERT_RESULT_MAX];
127 ubyte output_semantic_name[VERT_RESULT_MAX];
128 ubyte output_semantic_index[VERT_RESULT_MAX];
129 GLuint num_outputs;
130
131 /** List of translated varients of this vertex program.
132 */
133 struct st_vp_varient *varients;
134 };
135
136
137 static INLINE struct st_fragment_program *
138 st_fragment_program( struct gl_fragment_program *fp )
139 {
140 return (struct st_fragment_program *)fp;
141 }
142
143
144 static INLINE struct st_vertex_program *
145 st_vertex_program( struct gl_vertex_program *vp )
146 {
147 return (struct st_vertex_program *)vp;
148 }
149
150
151 static INLINE void
152 st_reference_vertprog(struct st_context *st,
153 struct st_vertex_program **ptr,
154 struct st_vertex_program *prog)
155 {
156 _mesa_reference_program(st->ctx,
157 (struct gl_program **) ptr,
158 (struct gl_program *) prog);
159 }
160
161 static INLINE void
162 st_reference_fragprog(struct st_context *st,
163 struct st_fragment_program **ptr,
164 struct st_fragment_program *prog)
165 {
166 _mesa_reference_program(st->ctx,
167 (struct gl_program **) ptr,
168 (struct gl_program *) prog);
169 }
170
171
172 extern void
173 st_translate_fragment_program(struct st_context *st,
174 struct st_fragment_program *fp,
175 const GLuint inputMapping[]);
176
177
178 /* Called after program string change, discard all previous
179 * compilation results.
180 */
181 extern void
182 st_prepare_vertex_program(struct st_context *st,
183 struct st_vertex_program *stvp);
184
185 extern struct st_vp_varient *
186 st_translate_vertex_program(struct st_context *st,
187 struct st_vertex_program *stvp,
188 const struct st_vp_varient_key *key);
189
190 void
191 st_vp_release_varients( struct st_context *st,
192 struct st_vertex_program *stvp );
193
194 extern void
195 st_print_shaders(GLcontext *ctx);
196
197
198 #endif