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_state.h"
40 #include "st_context.h"
44 * Derived from Mesa gl_fragment_program:
46 struct st_fragment_program
48 struct gl_fragment_program Base
;
51 struct pipe_shader_state tgsi
;
54 /** Program prefixed with glBitmap prologue */
55 struct st_fragment_program
*bitmap_program
;
61 struct st_vp_varient_key
63 boolean passthrough_edgeflags
;
68 * This represents a vertex program, especially translated to match
69 * the inputs of a particular fragment shader.
73 /* Parameters which generated this translated version of a vertex
76 struct st_vp_varient_key key
;
79 * TGSI tokens (to later generate a 'draw' module shader for
80 * selection/feedback/rasterpos)
82 struct pipe_shader_state tgsi
;
84 /** Driver's compiled shader */
87 /** For using our private draw module (glRasterPos) */
88 struct draw_vertex_shader
*draw_shader
;
90 /** Next in linked list */
91 struct st_vp_varient
*next
;
93 /** similar to that in st_vertex_program, but with information about edgeflags too */
99 * Derived from Mesa gl_fragment_program:
101 struct st_vertex_program
103 struct gl_vertex_program Base
; /**< The Mesa vertex program */
104 GLuint serialNo
, lastSerialNo
;
106 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
107 GLuint input_to_index
[VERT_ATTRIB_MAX
];
108 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
109 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
112 /** Maps VERT_RESULT_x to slot */
113 GLuint result_to_output
[VERT_RESULT_MAX
];
114 ubyte output_semantic_name
[VERT_RESULT_MAX
];
115 ubyte output_semantic_index
[VERT_RESULT_MAX
];
118 /** List of translated varients of this vertex program.
120 struct st_vp_varient
*varients
;
124 * Derived from Mesa gl_geometry_program:
126 struct st_geometry_program
128 struct gl_geometry_program Base
; /**< The Mesa geometry program */
131 /** map GP input back to VP output */
132 GLuint input_map
[PIPE_MAX_SHADER_INPUTS
];
134 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
135 GLuint input_to_index
[GEOM_ATTRIB_MAX
];
136 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
137 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
141 GLuint input_to_slot
[GEOM_ATTRIB_MAX
]; /**< Maps GEOM_ATTRIB_x to slot */
142 GLuint num_input_slots
;
144 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
145 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
147 struct pipe_shader_state tgsi
;
151 static INLINE
struct st_fragment_program
*
152 st_fragment_program( struct gl_fragment_program
*fp
)
154 return (struct st_fragment_program
*)fp
;
158 static INLINE
struct st_vertex_program
*
159 st_vertex_program( struct gl_vertex_program
*vp
)
161 return (struct st_vertex_program
*)vp
;
164 static INLINE
struct st_geometry_program
*
165 st_geometry_program( struct gl_geometry_program
*vp
)
167 return (struct st_geometry_program
*)vp
;
171 st_reference_vertprog(struct st_context
*st
,
172 struct st_vertex_program
**ptr
,
173 struct st_vertex_program
*prog
)
175 _mesa_reference_program(st
->ctx
,
176 (struct gl_program
**) ptr
,
177 (struct gl_program
*) prog
);
181 st_reference_geomprog(struct st_context
*st
,
182 struct st_geometry_program
**ptr
,
183 struct st_geometry_program
*prog
)
185 _mesa_reference_program(st
->ctx
,
186 (struct gl_program
**) ptr
,
187 (struct gl_program
*) prog
);
191 st_reference_fragprog(struct st_context
*st
,
192 struct st_fragment_program
**ptr
,
193 struct st_fragment_program
*prog
)
195 _mesa_reference_program(st
->ctx
,
196 (struct gl_program
**) ptr
,
197 (struct gl_program
*) prog
);
202 st_translate_fragment_program(struct st_context
*st
,
203 struct st_fragment_program
*fp
);
206 st_translate_geometry_program(struct st_context
*st
,
207 struct st_geometry_program
*stgp
);
209 /* Called after program string change, discard all previous
210 * compilation results.
213 st_prepare_vertex_program(struct st_context
*st
,
214 struct st_vertex_program
*stvp
);
216 extern struct st_vp_varient
*
217 st_translate_vertex_program(struct st_context
*st
,
218 struct st_vertex_program
*stvp
,
219 const struct st_vp_varient_key
*key
);
222 st_vp_release_varients( struct st_context
*st
,
223 struct st_vertex_program
*stvp
);
226 st_print_shaders(GLcontext
*ctx
);