draw: corrections to allow for different cliptest cases
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_derived.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_private.h"
34 #include "lp_context.h"
35 #include "lp_screen.h"
36 #include "lp_setup.h"
37 #include "lp_state.h"
38
39
40
41 /**
42 * The vertex info describes how to convert the post-transformed vertices
43 * (simple float[][4]) used by the 'draw' module into vertices for
44 * rasterization.
45 *
46 * This function validates the vertex layout.
47 */
48 static void
49 compute_vertex_info(struct llvmpipe_context *llvmpipe)
50 {
51 const struct lp_fragment_shader *lpfs = llvmpipe->fs;
52 struct vertex_info *vinfo = &llvmpipe->vertex_info;
53 struct lp_shader_input *inputs = llvmpipe->inputs;
54 unsigned vs_index;
55 uint i;
56
57 /*
58 * Match FS inputs against VS outputs, emitting the necessary attributes.
59 */
60
61 vinfo->num_attribs = 0;
62
63 vs_index = draw_find_shader_output(llvmpipe->draw,
64 TGSI_SEMANTIC_POSITION,
65 0);
66
67 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index);
68
69 for (i = 0; i < lpfs->info.num_inputs; i++) {
70 /*
71 * Search for each input in current vs output:
72 */
73
74 vs_index = draw_find_shader_output(llvmpipe->draw,
75 lpfs->info.input_semantic_name[i],
76 lpfs->info.input_semantic_index[i]);
77 if (vs_index < 0) {
78 /*
79 * This can happen with sprite coordinates - the vertex
80 * shader doesn't need to provide an output as we generate
81 * them internally. However, lets keep pretending that there
82 * is something there to not confuse other code.
83 */
84 vs_index = 0;
85 }
86
87 /* This can be pre-computed, except for flatshade:
88 */
89 inputs[i].usage_mask = lpfs->info.input_usage_mask[i];
90
91 switch (lpfs->info.input_interpolate[i]) {
92 case TGSI_INTERPOLATE_CONSTANT:
93 inputs[i].interp = LP_INTERP_CONSTANT;
94 break;
95 case TGSI_INTERPOLATE_LINEAR:
96 inputs[i].interp = LP_INTERP_LINEAR;
97 break;
98 case TGSI_INTERPOLATE_PERSPECTIVE:
99 inputs[i].interp = LP_INTERP_PERSPECTIVE;
100 break;
101 default:
102 assert(0);
103 break;
104 }
105
106 switch (lpfs->info.input_semantic_name[i]) {
107 case TGSI_SEMANTIC_FACE:
108 inputs[i].interp = LP_INTERP_FACING;
109 break;
110 case TGSI_SEMANTIC_POSITION:
111 /* Position was already emitted above
112 */
113 inputs[i].interp = LP_INTERP_POSITION;
114 inputs[i].src_index = 0;
115 continue;
116 case TGSI_SEMANTIC_COLOR:
117 /* Colors are linearly inputs[i].interpolated in the fragment shader
118 * even when flatshading is active. This just tells the
119 * setup module to use coefficients with ddx==0 and
120 * ddy==0.
121 */
122 if (llvmpipe->rasterizer->flatshade)
123 inputs[i].interp = LP_INTERP_CONSTANT;
124 break;
125
126 default:
127 break;
128 }
129
130 /*
131 * Emit the requested fs attribute for all but position.
132 */
133
134 inputs[i].src_index = vinfo->num_attribs;
135 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index);
136 }
137
138 /* Figure out if we need pointsize as well.
139 */
140 vs_index = draw_find_shader_output(llvmpipe->draw,
141 TGSI_SEMANTIC_PSIZE, 0);
142
143 if (vs_index > 0) {
144 llvmpipe->psize_slot = vinfo->num_attribs;
145 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT, vs_index);
146 }
147
148 llvmpipe->num_inputs = lpfs->info.num_inputs;
149
150 draw_compute_vertex_size(vinfo);
151
152 lp_setup_set_vertex_info(llvmpipe->setup, vinfo);
153
154 lp_setup_set_fs_inputs(llvmpipe->setup,
155 inputs,
156 lpfs->info.num_inputs);
157 }
158
159
160 /**
161 * Handle state changes.
162 * Called just prior to drawing anything (pipe::draw_arrays(), etc).
163 *
164 * Hopefully this will remain quite simple, otherwise need to pull in
165 * something like the state tracker mechanism.
166 */
167 void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
168 {
169 struct llvmpipe_screen *lp_screen = llvmpipe_screen(llvmpipe->pipe.screen);
170
171 /* Check for updated textures.
172 */
173 if (llvmpipe->tex_timestamp != lp_screen->timestamp) {
174 llvmpipe->tex_timestamp = lp_screen->timestamp;
175 llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
176 }
177
178 if (llvmpipe->dirty & (LP_NEW_RASTERIZER |
179 LP_NEW_FS |
180 LP_NEW_VS))
181 compute_vertex_info( llvmpipe );
182
183 if (llvmpipe->dirty & (LP_NEW_FS |
184 LP_NEW_BLEND |
185 LP_NEW_SCISSOR |
186 LP_NEW_DEPTH_STENCIL_ALPHA |
187 LP_NEW_RASTERIZER |
188 LP_NEW_SAMPLER |
189 LP_NEW_SAMPLER_VIEW |
190 LP_NEW_QUERY))
191 llvmpipe_update_fs( llvmpipe );
192
193 if (llvmpipe->dirty & LP_NEW_BLEND_COLOR)
194 lp_setup_set_blend_color(llvmpipe->setup,
195 &llvmpipe->blend_color);
196
197 if (llvmpipe->dirty & LP_NEW_SCISSOR)
198 lp_setup_set_scissor(llvmpipe->setup, &llvmpipe->scissor);
199
200 if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA) {
201 lp_setup_set_alpha_ref_value(llvmpipe->setup,
202 llvmpipe->depth_stencil->alpha.ref_value);
203 lp_setup_set_stencil_ref_values(llvmpipe->setup,
204 llvmpipe->stencil_ref.ref_value);
205 }
206
207 if (llvmpipe->dirty & LP_NEW_CONSTANTS)
208 lp_setup_set_fs_constants(llvmpipe->setup,
209 llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]);
210
211 if (llvmpipe->dirty & (LP_NEW_SAMPLER_VIEW |
212 LP_NEW_SAMPLER))
213 lp_setup_set_fragment_sampler_views(llvmpipe->setup,
214 llvmpipe->num_fragment_sampler_views,
215 llvmpipe->fragment_sampler_views,
216 llvmpipe->sampler);
217
218 llvmpipe->dirty = 0;
219 }
220