llvmpipe: Remove unnecessary headers.
[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_state.h"
37
38
39 /**
40 * Mark the current vertex layout as "invalid".
41 * We'll validate the vertex layout later, when we start to actually
42 * render a point or line or tri.
43 */
44 static void
45 invalidate_vertex_layout(struct llvmpipe_context *llvmpipe)
46 {
47 llvmpipe->vertex_info.num_attribs = 0;
48 }
49
50
51 /**
52 * The vertex info describes how to convert the post-transformed vertices
53 * (simple float[][4]) used by the 'draw' module into vertices for
54 * rasterization.
55 *
56 * This function validates the vertex layout and returns a pointer to a
57 * vertex_info object.
58 */
59 struct vertex_info *
60 llvmpipe_get_vertex_info(struct llvmpipe_context *llvmpipe)
61 {
62 struct vertex_info *vinfo = &llvmpipe->vertex_info;
63
64 if (vinfo->num_attribs == 0) {
65 /* compute vertex layout now */
66 const struct lp_fragment_shader *lpfs = llvmpipe->fs;
67 struct vertex_info *vinfo_vbuf = &llvmpipe->vertex_info_vbuf;
68 const uint num = draw_current_shader_outputs(llvmpipe->draw);
69 uint i;
70
71 /* Tell draw_vbuf to simply emit the whole post-xform vertex
72 * as-is. No longer any need to try and emit draw vertex_header
73 * info.
74 */
75 vinfo_vbuf->num_attribs = 0;
76 for (i = 0; i < num; i++) {
77 draw_emit_vertex_attr(vinfo_vbuf, EMIT_4F, INTERP_PERSPECTIVE, i);
78 }
79 draw_compute_vertex_size(vinfo_vbuf);
80
81 /*
82 * Loop over fragment shader inputs, searching for the matching output
83 * from the vertex shader.
84 */
85 vinfo->num_attribs = 0;
86 for (i = 0; i < lpfs->info.num_inputs; i++) {
87 int src;
88 enum interp_mode interp;
89
90 switch (lpfs->info.input_interpolate[i]) {
91 case TGSI_INTERPOLATE_CONSTANT:
92 interp = INTERP_CONSTANT;
93 break;
94 case TGSI_INTERPOLATE_LINEAR:
95 interp = INTERP_LINEAR;
96 break;
97 case TGSI_INTERPOLATE_PERSPECTIVE:
98 interp = INTERP_PERSPECTIVE;
99 break;
100 default:
101 assert(0);
102 interp = INTERP_LINEAR;
103 }
104
105 switch (lpfs->info.input_semantic_name[i]) {
106 case TGSI_SEMANTIC_POSITION:
107 interp = INTERP_POS;
108 break;
109
110 case TGSI_SEMANTIC_COLOR:
111 if (llvmpipe->rasterizer->flatshade) {
112 interp = INTERP_CONSTANT;
113 }
114 break;
115 }
116
117 /* this includes texcoords and varying vars */
118 src = draw_find_shader_output(llvmpipe->draw,
119 lpfs->info.input_semantic_name[i],
120 lpfs->info.input_semantic_index[i]);
121 draw_emit_vertex_attr(vinfo, EMIT_4F, interp, src);
122 }
123
124 llvmpipe->psize_slot = draw_find_shader_output(llvmpipe->draw,
125 TGSI_SEMANTIC_PSIZE, 0);
126 if (llvmpipe->psize_slot > 0) {
127 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT,
128 llvmpipe->psize_slot);
129 }
130
131 draw_compute_vertex_size(vinfo);
132 }
133
134 return vinfo;
135 }
136
137
138 /**
139 * Called from vbuf module.
140 *
141 * Note that there's actually two different vertex layouts in llvmpipe.
142 *
143 * The normal one is computed in llvmpipe_get_vertex_info() above and is
144 * used by the point/line/tri "setup" code.
145 *
146 * The other one (this one) is only used by the vbuf module (which is
147 * not normally used by default but used in testing). For the vbuf module,
148 * we basically want to pass-through the draw module's vertex layout as-is.
149 * When the llvmpipe vbuf code begins drawing, the normal vertex layout
150 * will come into play again.
151 */
152 struct vertex_info *
153 llvmpipe_get_vbuf_vertex_info(struct llvmpipe_context *llvmpipe)
154 {
155 (void) llvmpipe_get_vertex_info(llvmpipe);
156 return &llvmpipe->vertex_info_vbuf;
157 }
158
159
160 /**
161 * Recompute cliprect from scissor bounds, scissor enable and surface size.
162 */
163 static void
164 compute_cliprect(struct llvmpipe_context *lp)
165 {
166 /* LP_NEW_FRAMEBUFFER
167 */
168 uint surfWidth = lp->framebuffer.width;
169 uint surfHeight = lp->framebuffer.height;
170
171 /* LP_NEW_RASTERIZER
172 */
173 if (lp->rasterizer->scissor) {
174
175 /* LP_NEW_SCISSOR
176 *
177 * clip to scissor rect:
178 */
179 lp->cliprect.minx = MAX2(lp->scissor.minx, 0);
180 lp->cliprect.miny = MAX2(lp->scissor.miny, 0);
181 lp->cliprect.maxx = MIN2(lp->scissor.maxx, surfWidth);
182 lp->cliprect.maxy = MIN2(lp->scissor.maxy, surfHeight);
183 }
184 else {
185 /* clip to surface bounds */
186 lp->cliprect.minx = 0;
187 lp->cliprect.miny = 0;
188 lp->cliprect.maxx = surfWidth;
189 lp->cliprect.maxy = surfHeight;
190 }
191 }
192
193
194 /* Hopefully this will remain quite simple, otherwise need to pull in
195 * something like the state tracker mechanism.
196 */
197 void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
198 {
199 struct llvmpipe_screen *lp_screen = llvmpipe_screen(llvmpipe->pipe.screen);
200
201 /* Check for updated textures.
202 */
203 if (llvmpipe->tex_timestamp != lp_screen->timestamp) {
204 llvmpipe->tex_timestamp = lp_screen->timestamp;
205 llvmpipe->dirty |= LP_NEW_TEXTURE;
206 }
207
208 if (llvmpipe->dirty & (LP_NEW_SAMPLER |
209 LP_NEW_TEXTURE)) {
210 /* TODO */
211 }
212
213 if (llvmpipe->dirty & (LP_NEW_RASTERIZER |
214 LP_NEW_FS |
215 LP_NEW_VS))
216 invalidate_vertex_layout( llvmpipe );
217
218 if (llvmpipe->dirty & (LP_NEW_SCISSOR |
219 LP_NEW_RASTERIZER |
220 LP_NEW_FRAMEBUFFER))
221 compute_cliprect(llvmpipe);
222
223 if (llvmpipe->dirty & (LP_NEW_FS |
224 LP_NEW_BLEND |
225 LP_NEW_DEPTH_STENCIL_ALPHA |
226 LP_NEW_SAMPLER |
227 LP_NEW_TEXTURE))
228 llvmpipe_update_fs( llvmpipe );
229
230
231 llvmpipe->dirty = 0;
232 }