1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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"
43 #include "pipe/p_shader_tokens.h"
44 #include "util/u_simple_shaders.h"
45 #include "cso_cache/cso_context.h"
47 #include "st_context.h"
49 #include "st_program.h"
53 * Update fragment program state/atom. This involves translating the
54 * Mesa fragment program into a gallium fragment program and binding it.
57 update_fp( struct st_context
*st
)
59 struct st_fragment_program
*stfp
;
60 struct st_fp_variant_key key
;
62 assert(st
->ctx
->FragmentProgram
._Current
);
63 stfp
= st_fragment_program(st
->ctx
->FragmentProgram
._Current
);
64 assert(stfp
->Base
.Base
.Target
== GL_FRAGMENT_PROGRAM_ARB
);
66 memset(&key
, 0, sizeof(key
));
70 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
71 st
->ctx
->Color
._ClampFragmentColor
;
73 /* Ignore sample qualifier while computing this flag. */
74 key
.persample_shading
=
75 _mesa_get_min_invocations_per_fragment(st
->ctx
, &stfp
->Base
, true) > 1;
77 st
->fp_variant
= st_get_fp_variant(st
, stfp
, &key
);
79 st_reference_fragprog(st
, &st
->fp
, stfp
);
81 cso_set_fragment_shader_handle(st
->cso_context
,
82 st
->fp_variant
->driver_shader
);
86 const struct st_tracked_state st_update_fp
= {
87 "st_update_fp", /* name */
89 _NEW_BUFFERS
| _NEW_MULTISAMPLE
, /* mesa */
90 ST_NEW_FRAGMENT_PROGRAM
/* st */
92 update_fp
/* update */
98 * Update vertex program state/atom. This involves translating the
99 * Mesa vertex program into a gallium fragment program and binding it.
102 update_vp( struct st_context
*st
)
104 struct st_vertex_program
*stvp
;
105 struct st_vp_variant_key key
;
107 /* find active shader and params -- Should be covered by
108 * ST_NEW_VERTEX_PROGRAM
110 assert(st
->ctx
->VertexProgram
._Current
);
111 stvp
= st_vertex_program(st
->ctx
->VertexProgram
._Current
);
112 assert(stvp
->Base
.Base
.Target
== GL_VERTEX_PROGRAM_ARB
);
114 memset(&key
, 0, sizeof key
);
115 key
.st
= st
; /* variants are per-context */
117 /* When this is true, we will add an extra input to the vertex
118 * shader translation (for edgeflags), an extra output with
119 * edgeflag semantics, and extend the vertex shader to pass through
120 * the input to the output. We'll need to use similar logic to set
121 * up the extra vertex_element input for edgeflags.
123 key
.passthrough_edgeflags
= st
->vertdata_edgeflags
;
125 key
.clamp_color
= st
->clamp_vert_color_in_shader
&&
126 st
->ctx
->Light
._ClampVertexColor
&&
127 (stvp
->Base
.Base
.OutputsWritten
&
133 st
->vp_variant
= st_get_vp_variant(st
, stvp
, &key
);
135 st_reference_vertprog(st
, &st
->vp
, stvp
);
137 cso_set_vertex_shader_handle(st
->cso_context
,
138 st
->vp_variant
->driver_shader
);
140 st
->vertex_result_to_slot
= stvp
->result_to_output
;
144 const struct st_tracked_state st_update_vp
= {
145 "st_update_vp", /* name */
148 ST_NEW_VERTEX_PROGRAM
/* st */
150 update_vp
/* update */
156 update_gp( struct st_context
*st
)
158 struct st_geometry_program
*stgp
;
159 struct st_gp_variant_key key
;
161 if (!st
->ctx
->GeometryProgram
._Current
) {
162 cso_set_geometry_shader_handle(st
->cso_context
, NULL
);
166 stgp
= st_geometry_program(st
->ctx
->GeometryProgram
._Current
);
167 assert(stgp
->Base
.Base
.Target
== GL_GEOMETRY_PROGRAM_NV
);
169 memset(&key
, 0, sizeof(key
));
172 st
->gp_variant
= st_get_gp_variant(st
, stgp
, &key
);
174 st_reference_geomprog(st
, &st
->gp
, stgp
);
176 cso_set_geometry_shader_handle(st
->cso_context
,
177 st
->gp_variant
->driver_shader
);
180 const struct st_tracked_state st_update_gp
= {
181 "st_update_gp", /* name */
184 ST_NEW_GEOMETRY_PROGRAM
/* st */
186 update_gp
/* update */
192 update_tcp( struct st_context
*st
)
194 struct st_tessctrl_program
*sttcp
;
195 struct st_tcp_variant_key key
;
197 if (!st
->ctx
->TessCtrlProgram
._Current
) {
198 cso_set_tessctrl_shader_handle(st
->cso_context
, NULL
);
202 sttcp
= st_tessctrl_program(st
->ctx
->TessCtrlProgram
._Current
);
203 assert(sttcp
->Base
.Base
.Target
== GL_TESS_CONTROL_PROGRAM_NV
);
205 memset(&key
, 0, sizeof(key
));
208 st
->tcp_variant
= st_get_tcp_variant(st
, sttcp
, &key
);
210 st_reference_tesscprog(st
, &st
->tcp
, sttcp
);
212 cso_set_tessctrl_shader_handle(st
->cso_context
,
213 st
->tcp_variant
->driver_shader
);
216 const struct st_tracked_state st_update_tcp
= {
217 "st_update_tcp", /* name */
220 ST_NEW_TESSCTRL_PROGRAM
/* st */
222 update_tcp
/* update */
228 update_tep( struct st_context
*st
)
230 struct st_tesseval_program
*sttep
;
231 struct st_tep_variant_key key
;
233 if (!st
->ctx
->TessEvalProgram
._Current
) {
234 cso_set_tesseval_shader_handle(st
->cso_context
, NULL
);
238 sttep
= st_tesseval_program(st
->ctx
->TessEvalProgram
._Current
);
239 assert(sttep
->Base
.Base
.Target
== GL_TESS_EVALUATION_PROGRAM_NV
);
241 memset(&key
, 0, sizeof(key
));
244 st
->tep_variant
= st_get_tep_variant(st
, sttep
, &key
);
246 st_reference_tesseprog(st
, &st
->tep
, sttep
);
248 cso_set_tesseval_shader_handle(st
->cso_context
,
249 st
->tep_variant
->driver_shader
);
252 const struct st_tracked_state st_update_tep
= {
253 "st_update_tep", /* name */
256 ST_NEW_TESSEVAL_PROGRAM
/* st */
258 update_tep
/* update */