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"
41 #include "st_glsl_to_tgsi.h"
44 /** Fragment program variant key */
45 struct st_fp_variant_key
47 struct st_context
*st
; /**< variants are per-context */
50 GLuint bitmap
:1; /**< glBitmap variant? */
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) */
62 * Variant of a fragment program.
66 /** Parameters which generated this version of fragment program */
67 struct st_fp_variant_key key
;
69 /** Driver's compiled shader */
72 /** For glBitmap variants */
73 struct gl_program_parameter_list
*parameters
;
76 /** next in linked list */
77 struct st_fp_variant
*next
;
82 * Derived from Mesa gl_fragment_program:
84 struct st_fragment_program
86 struct gl_fragment_program Base
;
87 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
89 struct pipe_shader_state tgsi
;
91 struct st_fp_variant
*variants
;
96 /** Vertex program variant key */
97 struct st_vp_variant_key
99 struct st_context
*st
; /**< variants are per-context */
100 boolean passthrough_edgeflags
;
105 * This represents a vertex program, especially translated to match
106 * the inputs of a particular fragment shader.
110 /* Parameters which generated this translated version of a vertex
113 struct st_vp_variant_key key
;
116 * TGSI tokens (to later generate a 'draw' module shader for
117 * selection/feedback/rasterpos)
119 struct pipe_shader_state tgsi
;
121 /** Driver's compiled shader */
124 /** For using our private draw module (glRasterPos) */
125 struct draw_vertex_shader
*draw_shader
;
127 /** Next in linked list */
128 struct st_vp_variant
*next
;
130 /** similar to that in st_vertex_program, but with edgeflags info too */
136 * Derived from Mesa gl_fragment_program:
138 struct st_vertex_program
140 struct gl_vertex_program Base
; /**< The Mesa vertex program */
141 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
143 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
144 GLuint input_to_index
[VERT_ATTRIB_MAX
];
145 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
146 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
149 /** Maps VERT_RESULT_x to slot */
150 GLuint result_to_output
[VERT_RESULT_MAX
];
151 ubyte output_semantic_name
[VERT_RESULT_MAX
];
152 ubyte output_semantic_index
[VERT_RESULT_MAX
];
155 /** List of translated variants of this vertex program.
157 struct st_vp_variant
*variants
;
162 /** Geometry program variant key */
163 struct st_gp_variant_key
165 struct st_context
*st
; /**< variants are per-context */
166 /* no other fields yet */
171 * Geometry program variant.
175 /* Parameters which generated this translated version of a vertex */
176 struct st_gp_variant_key key
;
180 struct st_gp_variant
*next
;
185 * Derived from Mesa gl_geometry_program:
187 struct st_geometry_program
189 struct gl_geometry_program Base
; /**< The Mesa geometry program */
190 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
192 /** map GP input back to VP output */
193 GLuint input_map
[PIPE_MAX_SHADER_INPUTS
];
195 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
196 GLuint input_to_index
[GEOM_ATTRIB_MAX
];
197 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
198 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
202 GLuint input_to_slot
[GEOM_ATTRIB_MAX
]; /**< Maps GEOM_ATTRIB_x to slot */
203 GLuint num_input_slots
;
205 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
206 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
208 struct pipe_shader_state tgsi
;
210 struct st_gp_variant
*variants
;
215 static INLINE
struct st_fragment_program
*
216 st_fragment_program( struct gl_fragment_program
*fp
)
218 return (struct st_fragment_program
*)fp
;
222 static INLINE
struct st_vertex_program
*
223 st_vertex_program( struct gl_vertex_program
*vp
)
225 return (struct st_vertex_program
*)vp
;
228 static INLINE
struct st_geometry_program
*
229 st_geometry_program( struct gl_geometry_program
*gp
)
231 return (struct st_geometry_program
*)gp
;
235 st_reference_vertprog(struct st_context
*st
,
236 struct st_vertex_program
**ptr
,
237 struct st_vertex_program
*prog
)
239 _mesa_reference_program(st
->ctx
,
240 (struct gl_program
**) ptr
,
241 (struct gl_program
*) prog
);
245 st_reference_geomprog(struct st_context
*st
,
246 struct st_geometry_program
**ptr
,
247 struct st_geometry_program
*prog
)
249 _mesa_reference_program(st
->ctx
,
250 (struct gl_program
**) ptr
,
251 (struct gl_program
*) prog
);
255 st_reference_fragprog(struct st_context
*st
,
256 struct st_fragment_program
**ptr
,
257 struct st_fragment_program
*prog
)
259 _mesa_reference_program(st
->ctx
,
260 (struct gl_program
**) ptr
,
261 (struct gl_program
*) prog
);
265 extern struct st_vp_variant
*
266 st_get_vp_variant(struct st_context
*st
,
267 struct st_vertex_program
*stvp
,
268 const struct st_vp_variant_key
*key
);
271 extern struct st_fp_variant
*
272 st_get_fp_variant(struct st_context
*st
,
273 struct st_fragment_program
*stfp
,
274 const struct st_fp_variant_key
*key
);
277 extern struct st_gp_variant
*
278 st_get_gp_variant(struct st_context
*st
,
279 struct st_geometry_program
*stgp
,
280 const struct st_gp_variant_key
*key
);
284 st_prepare_vertex_program(struct gl_context
*ctx
,
285 struct st_vertex_program
*stvp
);
288 st_prepare_fragment_program(struct gl_context
*ctx
,
289 struct st_fragment_program
*stfp
);
293 st_release_vp_variants( struct st_context
*st
,
294 struct st_vertex_program
*stvp
);
297 st_release_fp_variants( struct st_context
*st
,
298 struct st_fragment_program
*stfp
);
301 st_release_gp_variants(struct st_context
*st
,
302 struct st_geometry_program
*stgp
);
306 st_print_shaders(struct gl_context
*ctx
);
309 st_destroy_program_variants(struct st_context
*st
);