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 **************************************************************************/
29 * State validation for vertex/fragment shaders.
30 * Note that we have to delay most vertex/fragment shader translation
31 * until rendering time since the linkage between the vertex outputs and
32 * fragment inputs can vary depending on the pairing of shaders.
38 #include "main/imports.h"
39 #include "main/mtypes.h"
40 #include "program/program.h"
42 #include "pipe/p_context.h"
44 #include "util/u_simple_shaders.h"
46 #include "cso_cache/cso_context.h"
48 #include "st_context.h"
50 #include "st_program.h"
54 * Return pointer to a pass-through fragment shader.
55 * This shader is used when a texture is missing/incomplete.
58 get_passthrough_fs(struct st_context
*st
)
60 if (!st
->passthrough_fs
) {
62 util_make_fragment_passthrough_shader(st
->pipe
, TGSI_SEMANTIC_COLOR
,
63 TGSI_INTERPOLATE_PERSPECTIVE
,
67 return st
->passthrough_fs
;
72 * Update fragment program state/atom. This involves translating the
73 * Mesa fragment program into a gallium fragment program and binding it.
76 update_fp( struct st_context
*st
)
78 struct st_fragment_program
*stfp
;
79 struct st_fp_variant_key key
;
81 assert(st
->ctx
->FragmentProgram
._Current
);
82 stfp
= st_fragment_program(st
->ctx
->FragmentProgram
._Current
);
83 assert(stfp
->Base
.Base
.Target
== GL_FRAGMENT_PROGRAM_ARB
);
85 memset(&key
, 0, sizeof(key
));
89 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
90 st
->ctx
->Color
._ClampFragmentColor
;
92 st
->fp_variant
= st_get_fp_variant(st
, stfp
, &key
);
94 st_reference_fragprog(st
, &st
->fp
, stfp
);
96 if (st
->missing_textures
) {
97 /* use a pass-through frag shader that uses no textures */
98 void *fs
= get_passthrough_fs(st
);
99 cso_set_fragment_shader_handle(st
->cso_context
, fs
);
102 cso_set_fragment_shader_handle(st
->cso_context
,
103 st
->fp_variant
->driver_shader
);
108 const struct st_tracked_state st_update_fp
= {
109 "st_update_fp", /* name */
111 _NEW_BUFFERS
, /* mesa */
112 ST_NEW_FRAGMENT_PROGRAM
/* st */
114 update_fp
/* update */
120 * Update vertex program state/atom. This involves translating the
121 * Mesa vertex program into a gallium fragment program and binding it.
124 update_vp( struct st_context
*st
)
126 struct st_vertex_program
*stvp
;
127 struct st_vp_variant_key key
;
129 /* find active shader and params -- Should be covered by
130 * ST_NEW_VERTEX_PROGRAM
132 assert(st
->ctx
->VertexProgram
._Current
);
133 stvp
= st_vertex_program(st
->ctx
->VertexProgram
._Current
);
134 assert(stvp
->Base
.Base
.Target
== GL_VERTEX_PROGRAM_ARB
);
136 memset(&key
, 0, sizeof key
);
137 key
.st
= st
; /* variants are per-context */
139 /* When this is true, we will add an extra input to the vertex
140 * shader translation (for edgeflags), an extra output with
141 * edgeflag semantics, and extend the vertex shader to pass through
142 * the input to the output. We'll need to use similar logic to set
143 * up the extra vertex_element input for edgeflags.
144 * _NEW_POLYGON, ST_NEW_EDGEFLAGS_DATA
146 key
.passthrough_edgeflags
= (st
->vertdata_edgeflags
&& (
147 st
->ctx
->Polygon
.FrontMode
!= GL_FILL
||
148 st
->ctx
->Polygon
.BackMode
!= GL_FILL
));
150 key
.clamp_color
= st
->clamp_vert_color_in_shader
&&
151 st
->ctx
->Light
._ClampVertexColor
;
153 st
->vp_variant
= st_get_vp_variant(st
, stvp
, &key
);
155 st_reference_vertprog(st
, &st
->vp
, stvp
);
157 cso_set_vertex_shader_handle(st
->cso_context
,
158 st
->vp_variant
->driver_shader
);
160 st
->vertex_result_to_slot
= stvp
->result_to_output
;
164 const struct st_tracked_state st_update_vp
= {
165 "st_update_vp", /* name */
167 _NEW_POLYGON
, /* mesa */
168 ST_NEW_VERTEX_PROGRAM
| ST_NEW_EDGEFLAGS_DATA
/* st */
170 update_vp
/* update */
176 update_gp( struct st_context
*st
)
178 struct st_geometry_program
*stgp
;
179 struct st_gp_variant_key key
;
181 if (!st
->ctx
->GeometryProgram
._Current
) {
182 cso_set_geometry_shader_handle(st
->cso_context
, NULL
);
186 stgp
= st_geometry_program(st
->ctx
->GeometryProgram
._Current
);
187 assert(stgp
->Base
.Base
.Target
== MESA_GEOMETRY_PROGRAM
);
189 memset(&key
, 0, sizeof(key
));
192 st
->gp_variant
= st_get_gp_variant(st
, stgp
, &key
);
194 st_reference_geomprog(st
, &st
->gp
, stgp
);
196 cso_set_geometry_shader_handle(st
->cso_context
,
197 st
->gp_variant
->driver_shader
);
200 const struct st_tracked_state st_update_gp
= {
201 "st_update_gp", /* name */
204 ST_NEW_GEOMETRY_PROGRAM
/* st */
206 update_gp
/* update */