llvmpipe: remove tex tile cache and related code
[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 const enum interp_mode colorInterp
68 = llvmpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
69 struct vertex_info *vinfo_vbuf = &llvmpipe->vertex_info_vbuf;
70 const uint num = draw_num_vs_outputs(llvmpipe->draw);
71 uint i;
72
73 /* Tell draw_vbuf to simply emit the whole post-xform vertex
74 * as-is. No longer any need to try and emit draw vertex_header
75 * info.
76 */
77 vinfo_vbuf->num_attribs = 0;
78 for (i = 0; i < num; i++) {
79 draw_emit_vertex_attr(vinfo_vbuf, EMIT_4F, INTERP_PERSPECTIVE, i);
80 }
81 draw_compute_vertex_size(vinfo_vbuf);
82
83 /*
84 * Loop over fragment shader inputs, searching for the matching output
85 * from the vertex shader.
86 */
87 vinfo->num_attribs = 0;
88 for (i = 0; i < lpfs->info.num_inputs; i++) {
89 int src;
90 enum interp_mode interp;
91
92 switch (lpfs->info.input_interpolate[i]) {
93 case TGSI_INTERPOLATE_CONSTANT:
94 interp = INTERP_CONSTANT;
95 break;
96 case TGSI_INTERPOLATE_LINEAR:
97 interp = INTERP_LINEAR;
98 break;
99 case TGSI_INTERPOLATE_PERSPECTIVE:
100 interp = INTERP_PERSPECTIVE;
101 break;
102 default:
103 assert(0);
104 interp = INTERP_LINEAR;
105 }
106
107 switch (lpfs->info.input_semantic_name[i]) {
108 case TGSI_SEMANTIC_POSITION:
109 src = draw_find_vs_output(llvmpipe->draw,
110 TGSI_SEMANTIC_POSITION, 0);
111 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, src);
112 break;
113
114 case TGSI_SEMANTIC_COLOR:
115 src = draw_find_vs_output(llvmpipe->draw, TGSI_SEMANTIC_COLOR,
116 lpfs->info.input_semantic_index[i]);
117 draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
118 break;
119
120 case TGSI_SEMANTIC_FOG:
121 src = draw_find_vs_output(llvmpipe->draw, TGSI_SEMANTIC_FOG, 0);
122 draw_emit_vertex_attr(vinfo, EMIT_4F, interp, src);
123 break;
124
125 case TGSI_SEMANTIC_GENERIC:
126 case TGSI_SEMANTIC_FACE:
127 /* this includes texcoords and varying vars */
128 src = draw_find_vs_output(llvmpipe->draw, TGSI_SEMANTIC_GENERIC,
129 lpfs->info.input_semantic_index[i]);
130 draw_emit_vertex_attr(vinfo, EMIT_4F, interp, src);
131 break;
132
133 default:
134 assert(0);
135 }
136 }
137
138 llvmpipe->psize_slot = draw_find_vs_output(llvmpipe->draw,
139 TGSI_SEMANTIC_PSIZE, 0);
140 if (llvmpipe->psize_slot > 0) {
141 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT,
142 llvmpipe->psize_slot);
143 }
144
145 draw_compute_vertex_size(vinfo);
146 }
147
148 return vinfo;
149 }
150
151
152 /**
153 * Called from vbuf module.
154 *
155 * Note that there's actually two different vertex layouts in llvmpipe.
156 *
157 * The normal one is computed in llvmpipe_get_vertex_info() above and is
158 * used by the point/line/tri "setup" code.
159 *
160 * The other one (this one) is only used by the vbuf module (which is
161 * not normally used by default but used in testing). For the vbuf module,
162 * we basically want to pass-through the draw module's vertex layout as-is.
163 * When the llvmpipe vbuf code begins drawing, the normal vertex layout
164 * will come into play again.
165 */
166 struct vertex_info *
167 llvmpipe_get_vbuf_vertex_info(struct llvmpipe_context *llvmpipe)
168 {
169 (void) llvmpipe_get_vertex_info(llvmpipe);
170 return &llvmpipe->vertex_info_vbuf;
171 }
172
173
174 /**
175 * Recompute cliprect from scissor bounds, scissor enable and surface size.
176 */
177 static void
178 compute_cliprect(struct llvmpipe_context *lp)
179 {
180 /* LP_NEW_FRAMEBUFFER
181 */
182 uint surfWidth = lp->framebuffer.width;
183 uint surfHeight = lp->framebuffer.height;
184
185 /* LP_NEW_RASTERIZER
186 */
187 if (lp->rasterizer->scissor) {
188
189 /* LP_NEW_SCISSOR
190 *
191 * clip to scissor rect:
192 */
193 lp->cliprect.minx = MAX2(lp->scissor.minx, 0);
194 lp->cliprect.miny = MAX2(lp->scissor.miny, 0);
195 lp->cliprect.maxx = MIN2(lp->scissor.maxx, surfWidth);
196 lp->cliprect.maxy = MIN2(lp->scissor.maxy, surfHeight);
197 }
198 else {
199 /* clip to surface bounds */
200 lp->cliprect.minx = 0;
201 lp->cliprect.miny = 0;
202 lp->cliprect.maxx = surfWidth;
203 lp->cliprect.maxy = surfHeight;
204 }
205 }
206
207
208 static void
209 update_tgsi_samplers( struct llvmpipe_context *llvmpipe )
210 {
211 unsigned i;
212
213 /* vertex shader samplers */
214 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
215 llvmpipe->tgsi.vert_samplers[i].sampler = llvmpipe->sampler[i];
216 llvmpipe->tgsi.vert_samplers[i].texture = llvmpipe->texture[i];
217 llvmpipe->tgsi.vert_samplers[i].base.get_samples = lp_get_samples;
218 }
219
220 /* fragment shader samplers */
221 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
222 llvmpipe->tgsi.frag_samplers[i].sampler = llvmpipe->sampler[i];
223 llvmpipe->tgsi.frag_samplers[i].texture = llvmpipe->texture[i];
224 llvmpipe->tgsi.frag_samplers[i].base.get_samples = lp_get_samples;
225 }
226
227 llvmpipe->jit_context.samplers = (struct tgsi_sampler **)llvmpipe->tgsi.frag_samplers_list;
228 }
229
230 static void
231 update_culling()
232 {
233 if (lp->reduced_api_prim == PIPE_PRIM_TRIANGLES &&
234 lp->rasterizer->fill_cw == PIPE_POLYGON_MODE_FILL &&
235 lp->rasterizer->fill_ccw == PIPE_POLYGON_MODE_FILL) {
236 /* we'll do culling */
237 setup->winding = lp->rasterizer->cull_mode;
238 }
239 else {
240 /* 'draw' will do culling */
241 setup->winding = PIPE_WINDING_NONE;
242 }
243 }
244
245
246 /* Hopefully this will remain quite simple, otherwise need to pull in
247 * something like the state tracker mechanism.
248 */
249 void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
250 {
251 struct llvmpipe_screen *lp_screen = llvmpipe_screen(llvmpipe->pipe.screen);
252
253 /* Check for updated textures.
254 */
255 if (llvmpipe->tex_timestamp != lp_screen->timestamp) {
256 llvmpipe->tex_timestamp = lp_screen->timestamp;
257 llvmpipe->dirty |= LP_NEW_TEXTURE;
258 }
259
260 if (llvmpipe->dirty & (LP_NEW_SAMPLER |
261 LP_NEW_TEXTURE))
262 update_tgsi_samplers( llvmpipe );
263
264 if (llvmpipe->dirty & (LP_NEW_RASTERIZER |
265 LP_NEW_FS |
266 LP_NEW_VS))
267 invalidate_vertex_layout( llvmpipe );
268
269 if (llvmpipe->dirty & (LP_NEW_SCISSOR |
270 LP_NEW_RASTERIZER |
271 LP_NEW_FRAMEBUFFER))
272 compute_cliprect(llvmpipe);
273
274 if (llvmpipe->dirty & (LP_NEW_FS |
275 LP_NEW_BLEND |
276 LP_NEW_DEPTH_STENCIL_ALPHA |
277 LP_NEW_SAMPLER |
278 LP_NEW_TEXTURE))
279 llvmpipe_update_fs( llvmpipe );
280
281
282 llvmpipe->dirty = 0;
283 }
284
285
286 void llvmpipe_prepare( )
287 {
288 struct llvmpipe_context *lp = setup->llvmpipe;
289
290 if (lp->dirty) {
291 llvmpipe_update_derived(lp);
292 }
293
294 }