1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
37 #include "main/mtypes.h"
38 #include "program/program.h"
39 #include "pipe/p_shader_tokens.h"
42 struct cso_fragment_shader
;
43 struct cso_vertex_shader
;
47 * Derived from Mesa gl_fragment_program:
49 struct st_fragment_program
51 struct gl_fragment_program Base
;
54 struct pipe_shader_state tgsi
;
57 /** Program prefixed with glBitmap prologue */
58 struct st_fragment_program
*bitmap_program
;
64 struct st_vp_varient_key
66 boolean passthrough_edgeflags
;
71 * This represents a vertex program, especially translated to match
72 * the inputs of a particular fragment shader.
76 /* Parameters which generated this translated version of a vertex
79 struct st_vp_varient_key key
;
82 * TGSI tokens (to later generate a 'draw' module shader for
83 * selection/feedback/rasterpos)
85 struct pipe_shader_state tgsi
;
87 /** Driver's compiled shader */
90 /** For using our private draw module (glRasterPos) */
91 struct draw_vertex_shader
*draw_shader
;
93 /** Next in linked list */
94 struct st_vp_varient
*next
;
96 /** similar to that in st_vertex_program, but with information about edgeflags too */
102 * Derived from Mesa gl_fragment_program:
104 struct st_vertex_program
106 struct gl_vertex_program Base
; /**< The Mesa vertex program */
107 GLuint serialNo
, lastSerialNo
;
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
];
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
];
121 /** List of translated varients of this vertex program.
123 struct st_vp_varient
*varients
;
127 * Derived from Mesa gl_geometry_program:
129 struct st_geometry_program
131 struct gl_geometry_program Base
; /**< The Mesa geometry program */
134 /** map GP input back to VP output */
135 GLuint input_map
[PIPE_MAX_SHADER_INPUTS
];
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
];
144 GLuint input_to_slot
[GEOM_ATTRIB_MAX
]; /**< Maps GEOM_ATTRIB_x to slot */
145 GLuint num_input_slots
;
147 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
148 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
150 struct pipe_shader_state tgsi
;
154 static INLINE
struct st_fragment_program
*
155 st_fragment_program( struct gl_fragment_program
*fp
)
157 return (struct st_fragment_program
*)fp
;
161 static INLINE
struct st_vertex_program
*
162 st_vertex_program( struct gl_vertex_program
*vp
)
164 return (struct st_vertex_program
*)vp
;
167 static INLINE
struct st_geometry_program
*
168 st_geometry_program( struct gl_geometry_program
*vp
)
170 return (struct st_geometry_program
*)vp
;
174 st_reference_vertprog(struct st_context
*st
,
175 struct st_vertex_program
**ptr
,
176 struct st_vertex_program
*prog
)
178 _mesa_reference_program(st
->ctx
,
179 (struct gl_program
**) ptr
,
180 (struct gl_program
*) prog
);
184 st_reference_geomprog(struct st_context
*st
,
185 struct st_geometry_program
**ptr
,
186 struct st_geometry_program
*prog
)
188 _mesa_reference_program(st
->ctx
,
189 (struct gl_program
**) ptr
,
190 (struct gl_program
*) prog
);
194 st_reference_fragprog(struct st_context
*st
,
195 struct st_fragment_program
**ptr
,
196 struct st_fragment_program
*prog
)
198 _mesa_reference_program(st
->ctx
,
199 (struct gl_program
**) ptr
,
200 (struct gl_program
*) prog
);
205 st_translate_fragment_program(struct st_context
*st
,
206 struct st_fragment_program
*fp
);
209 st_translate_geometry_program(struct st_context
*st
,
210 struct st_geometry_program
*stgp
);
212 /* Called after program string change, discard all previous
213 * compilation results.
216 st_prepare_vertex_program(struct st_context
*st
,
217 struct st_vertex_program
*stvp
);
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
);
225 st_vp_release_varients( struct st_context
*st
,
226 struct st_vertex_program
*stvp
);
229 st_print_shaders(GLcontext
*ctx
);