Merge remote branch 'origin/7.8'
[mesa.git] / src / gallium / drivers / r300 / r300_state_derived.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #include "draw/draw_context.h"
25
26 #include "util/u_math.h"
27 #include "util/u_memory.h"
28
29 #include "r300_context.h"
30 #include "r300_fs.h"
31 #include "r300_screen.h"
32 #include "r300_shader_semantics.h"
33 #include "r300_state.h"
34 #include "r300_state_derived.h"
35 #include "r300_state_inlines.h"
36 #include "r300_vs.h"
37
38 /* r300_state_derived: Various bits of state which are dependent upon
39 * currently bound CSO data. */
40
41 enum r300_rs_swizzle {
42 SWIZ_XYZW = 0,
43 SWIZ_X001,
44 SWIZ_XY01,
45 };
46
47 static void r300_draw_emit_attrib(struct r300_context* r300,
48 enum attrib_emit emit,
49 enum interp_mode interp,
50 int index)
51 {
52 struct r300_vertex_shader* vs = r300->vs_state.state;
53 struct tgsi_shader_info* info = &vs->info;
54 int output;
55
56 output = draw_find_shader_output(r300->draw,
57 info->output_semantic_name[index],
58 info->output_semantic_index[index]);
59 draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output);
60 }
61
62 static void r300_draw_emit_all_attribs(struct r300_context* r300)
63 {
64 struct r300_vertex_shader* vs = r300->vs_state.state;
65 struct r300_shader_semantics* vs_outputs = &vs->outputs;
66 int i, gen_count;
67
68 /* Position. */
69 if (vs_outputs->pos != ATTR_UNUSED) {
70 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
71 vs_outputs->pos);
72 } else {
73 assert(0);
74 }
75
76 /* Point size. */
77 if (vs_outputs->psize != ATTR_UNUSED) {
78 r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS,
79 vs_outputs->psize);
80 }
81
82 /* Colors. */
83 for (i = 0; i < ATTR_COLOR_COUNT; i++) {
84 if (vs_outputs->color[i] != ATTR_UNUSED) {
85 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR,
86 vs_outputs->color[i]);
87 }
88 }
89
90 /* XXX Back-face colors. */
91
92 /* Texture coordinates. */
93 /* Only 8 generic vertex attributes can be used. If there are more,
94 * they won't be rasterized. */
95 gen_count = 0;
96 for (i = 0; i < ATTR_GENERIC_COUNT && gen_count < 8; i++) {
97 if (vs_outputs->generic[i] != ATTR_UNUSED) {
98 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
99 vs_outputs->generic[i]);
100 gen_count++;
101 }
102 }
103
104 /* Fog coordinates. */
105 if (gen_count < 8 && vs_outputs->fog != ATTR_UNUSED) {
106 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
107 vs_outputs->fog);
108 gen_count++;
109 }
110 }
111
112 /* Update the PSC tables for SW TCL, using Draw. */
113 static void r300_swtcl_vertex_psc(struct r300_context *r300)
114 {
115 struct r300_vertex_stream_state *vstream = r300->vertex_stream_state.state;
116 struct r300_vertex_shader* vs = r300->vs_state.state;
117 struct vertex_info* vinfo = &r300->vertex_info;
118 uint16_t type, swizzle;
119 enum pipe_format format;
120 unsigned i, attrib_count;
121 int* vs_output_tab = vs->stream_loc_notcl;
122
123 /* XXX hax */
124 memset(vstream, 0, sizeof(struct r300_vertex_stream_state));
125
126 /* For each Draw attribute, route it to the fragment shader according
127 * to the vs_output_tab. */
128 attrib_count = vinfo->num_attribs;
129 DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count);
130 for (i = 0; i < attrib_count; i++) {
131 DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d,"
132 " vs_output_tab %d\n", vinfo->attrib[i].src_index,
133 vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit,
134 vs_output_tab[i]);
135
136 /* Make sure we have a proper destination for our attribute. */
137 assert(vs_output_tab[i] != -1);
138
139 format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
140
141 /* Obtain the type of data in this attribute. */
142 type = r300_translate_vertex_data_type(format) |
143 vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
144
145 /* Obtain the swizzle for this attribute. Note that the default
146 * swizzle in the hardware is not XYZW! */
147 swizzle = r300_translate_vertex_data_swizzle(format);
148
149 /* Add the attribute to the PSC table. */
150 if (i & 1) {
151 vstream->vap_prog_stream_cntl[i >> 1] |= type << 16;
152 vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
153 } else {
154 vstream->vap_prog_stream_cntl[i >> 1] |= type;
155 vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
156 }
157 }
158
159 /* Set the last vector in the PSC. */
160 if (i) {
161 i -= 1;
162 }
163 vstream->vap_prog_stream_cntl[i >> 1] |=
164 (R300_LAST_VEC << (i & 1 ? 16 : 0));
165
166 vstream->count = (i >> 1) + 1;
167 r300->vertex_stream_state.dirty = TRUE;
168 r300->vertex_stream_state.size = (1 + vstream->count) * 2;
169 }
170
171 static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr,
172 boolean swizzle_0001)
173 {
174 rs->ip[id] |= R300_RS_COL_PTR(ptr);
175 if (swizzle_0001) {
176 rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_0001);
177 } else {
178 rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA);
179 }
180 rs->inst[id] |= R300_RS_INST_COL_ID(id);
181 }
182
183 static void r300_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset)
184 {
185 rs->inst[id] |= R300_RS_INST_COL_CN_WRITE |
186 R300_RS_INST_COL_ADDR(fp_offset);
187 }
188
189 static void r300_rs_tex(struct r300_rs_block* rs, int id, int ptr,
190 enum r300_rs_swizzle swiz)
191 {
192 if (swiz == SWIZ_X001) {
193 rs->ip[id] |= R300_RS_TEX_PTR(ptr*4) |
194 R300_RS_SEL_S(R300_RS_SEL_C0) |
195 R300_RS_SEL_T(R300_RS_SEL_K0) |
196 R300_RS_SEL_R(R300_RS_SEL_K0) |
197 R300_RS_SEL_Q(R300_RS_SEL_K1);
198 } else if (swiz == SWIZ_XY01) {
199 rs->ip[id] |= R300_RS_TEX_PTR(ptr*4) |
200 R300_RS_SEL_S(R300_RS_SEL_C0) |
201 R300_RS_SEL_T(R300_RS_SEL_C1) |
202 R300_RS_SEL_R(R300_RS_SEL_K0) |
203 R300_RS_SEL_Q(R300_RS_SEL_K1);
204 } else {
205 rs->ip[id] |= R300_RS_TEX_PTR(ptr*4) |
206 R300_RS_SEL_S(R300_RS_SEL_C0) |
207 R300_RS_SEL_T(R300_RS_SEL_C1) |
208 R300_RS_SEL_R(R300_RS_SEL_C2) |
209 R300_RS_SEL_Q(R300_RS_SEL_C3);
210 }
211 rs->inst[id] |= R300_RS_INST_TEX_ID(id);
212 }
213
214 static void r300_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset)
215 {
216 rs->inst[id] |= R300_RS_INST_TEX_CN_WRITE |
217 R300_RS_INST_TEX_ADDR(fp_offset);
218 }
219
220 static void r500_rs_col(struct r300_rs_block* rs, int id, int ptr,
221 boolean swizzle_0001)
222 {
223 rs->ip[id] |= R500_RS_COL_PTR(ptr);
224 if (swizzle_0001) {
225 rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_0001);
226 } else {
227 rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA);
228 }
229 rs->inst[id] |= R500_RS_INST_COL_ID(id);
230 }
231
232 static void r500_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset)
233 {
234 rs->inst[id] |= R500_RS_INST_COL_CN_WRITE |
235 R500_RS_INST_COL_ADDR(fp_offset);
236 }
237
238 static void r500_rs_tex(struct r300_rs_block* rs, int id, int ptr,
239 enum r300_rs_swizzle swiz)
240 {
241 int rs_tex_comp = ptr*4;
242
243 if (swiz == SWIZ_X001) {
244 rs->ip[id] |= R500_RS_SEL_S(rs_tex_comp) |
245 R500_RS_SEL_T(R500_RS_IP_PTR_K0) |
246 R500_RS_SEL_R(R500_RS_IP_PTR_K0) |
247 R500_RS_SEL_Q(R500_RS_IP_PTR_K1);
248 } else if (swiz == SWIZ_XY01) {
249 rs->ip[id] |= R500_RS_SEL_S(rs_tex_comp) |
250 R500_RS_SEL_T(rs_tex_comp + 1) |
251 R500_RS_SEL_R(R500_RS_IP_PTR_K0) |
252 R500_RS_SEL_Q(R500_RS_IP_PTR_K1);
253 } else {
254 rs->ip[id] |= R500_RS_SEL_S(rs_tex_comp) |
255 R500_RS_SEL_T(rs_tex_comp + 1) |
256 R500_RS_SEL_R(rs_tex_comp + 2) |
257 R500_RS_SEL_Q(rs_tex_comp + 3);
258 }
259 rs->inst[id] |= R500_RS_INST_TEX_ID(id);
260 }
261
262 static void r500_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset)
263 {
264 rs->inst[id] |= R500_RS_INST_TEX_CN_WRITE |
265 R500_RS_INST_TEX_ADDR(fp_offset);
266 }
267
268 /* Set up the RS block.
269 *
270 * This is the part of the chipset that actually does the rasterization
271 * of vertices into fragments. This is also the part of the chipset that
272 * locks up if any part of it is even slightly wrong. */
273 static void r300_update_rs_block(struct r300_context* r300,
274 struct r300_shader_semantics* vs_outputs,
275 struct r300_shader_semantics* fs_inputs)
276 {
277 struct r300_rs_block rs = { { 0 } };
278 int i, col_count = 0, tex_count = 0, fp_offset = 0, count;
279 void (*rX00_rs_col)(struct r300_rs_block*, int, int, boolean);
280 void (*rX00_rs_col_write)(struct r300_rs_block*, int, int);
281 void (*rX00_rs_tex)(struct r300_rs_block*, int, int, enum r300_rs_swizzle);
282 void (*rX00_rs_tex_write)(struct r300_rs_block*, int, int);
283 boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED ||
284 vs_outputs->bcolor[1] != ATTR_UNUSED;
285
286 if (r300->screen->caps.is_r500) {
287 rX00_rs_col = r500_rs_col;
288 rX00_rs_col_write = r500_rs_col_write;
289 rX00_rs_tex = r500_rs_tex;
290 rX00_rs_tex_write = r500_rs_tex_write;
291 } else {
292 rX00_rs_col = r300_rs_col;
293 rX00_rs_col_write = r300_rs_col_write;
294 rX00_rs_tex = r300_rs_tex;
295 rX00_rs_tex_write = r300_rs_tex_write;
296 }
297
298 /* Rasterize colors. */
299 for (i = 0; i < ATTR_COLOR_COUNT; i++) {
300 if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used ||
301 vs_outputs->color[1] != ATTR_UNUSED) {
302 /* Always rasterize if it's written by the VS,
303 * otherwise it locks up. */
304 rX00_rs_col(&rs, col_count, i, FALSE);
305
306 /* Write it to the FS input register if it's used by the FS. */
307 if (fs_inputs->color[i] != ATTR_UNUSED) {
308 rX00_rs_col_write(&rs, col_count, fp_offset);
309 fp_offset++;
310 }
311 col_count++;
312 } else {
313 /* Skip the FS input register, leave it uninitialized. */
314 /* If we try to set it to (0,0,0,1), it will lock up. */
315 if (fs_inputs->color[i] != ATTR_UNUSED) {
316 fp_offset++;
317 }
318 }
319 }
320
321 /* Rasterize texture coordinates. */
322 for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
323 bool sprite_coord = !!(r300->sprite_coord_enable & (1 << i));
324
325 if (vs_outputs->generic[i] != ATTR_UNUSED || sprite_coord) {
326 /* Always rasterize if it's written by the VS,
327 * otherwise it locks up. */
328 rX00_rs_tex(&rs, tex_count, tex_count,
329 sprite_coord ? SWIZ_XY01 : SWIZ_XYZW);
330
331 /* Write it to the FS input register if it's used by the FS. */
332 if (fs_inputs->generic[i] != ATTR_UNUSED) {
333 rX00_rs_tex_write(&rs, tex_count, fp_offset);
334 if (sprite_coord)
335 debug_printf("r300: SpriteCoord (generic index %i) is being written to reg %i\n", i, fp_offset);
336 fp_offset++;
337 }
338 tex_count++;
339 } else {
340 /* Skip the FS input register, leave it uninitialized. */
341 /* If we try to set it to (0,0,0,1), it will lock up. */
342 if (fs_inputs->generic[i] != ATTR_UNUSED) {
343 fp_offset++;
344 }
345 }
346 }
347
348 /* Rasterize fog coordinates. */
349 if (vs_outputs->fog != ATTR_UNUSED) {
350 /* Always rasterize if it's written by the VS,
351 * otherwise it locks up. */
352 rX00_rs_tex(&rs, tex_count, tex_count, SWIZ_X001);
353
354 /* Write it to the FS input register if it's used by the FS. */
355 if (fs_inputs->fog != ATTR_UNUSED) {
356 rX00_rs_tex_write(&rs, tex_count, fp_offset);
357 fp_offset++;
358 }
359 tex_count++;
360 } else {
361 /* Skip the FS input register, leave it uninitialized. */
362 /* If we try to set it to (0,0,0,1), it will lock up. */
363 if (fs_inputs->fog != ATTR_UNUSED) {
364 fp_offset++;
365 }
366 }
367
368 /* Rasterize WPOS. */
369 /* If the FS doesn't need it, it's not written by the VS. */
370 if (vs_outputs->wpos != ATTR_UNUSED && fs_inputs->wpos != ATTR_UNUSED) {
371 rX00_rs_tex(&rs, tex_count, tex_count, SWIZ_XYZW);
372 rX00_rs_tex_write(&rs, tex_count, fp_offset);
373
374 fp_offset++;
375 tex_count++;
376 }
377
378 /* Rasterize at least one color, or bad things happen. */
379 if (col_count == 0 && tex_count == 0) {
380 rX00_rs_col(&rs, 0, 0, TRUE);
381 col_count++;
382 }
383
384 rs.count = (tex_count*4) | (col_count << R300_IC_COUNT_SHIFT) |
385 R300_HIRES_EN;
386
387 count = MAX3(col_count, tex_count, 1);
388 rs.inst_count = count - 1;
389
390 /* Now, after all that, see if we actually need to update the state. */
391 if (memcmp(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block))) {
392 memcpy(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block));
393 r300->rs_block_state.size = 5 + count*2;
394 }
395 }
396
397 /* Update the shader-dependant states. */
398 static void r300_update_derived_shader_state(struct r300_context* r300)
399 {
400 struct r300_vertex_shader* vs = r300->vs_state.state;
401
402 r300_update_rs_block(r300, &vs->outputs, &r300_fs(r300)->shader->inputs);
403 }
404
405 static boolean r300_dsa_writes_depth_stencil(struct r300_dsa_state* dsa)
406 {
407 /* We are interested only in the cases when a new depth or stencil value
408 * can be written and changed. */
409
410 /* We might optionally check for [Z func: never] and inspect the stencil
411 * state in a similar fashion, but it's not terribly important. */
412 return (dsa->z_buffer_control & R300_Z_WRITE_ENABLE) ||
413 (dsa->stencil_ref_mask & R300_STENCILWRITEMASK_MASK) ||
414 ((dsa->z_buffer_control & R500_STENCIL_REFMASK_FRONT_BACK) &&
415 (dsa->stencil_ref_bf & R300_STENCILWRITEMASK_MASK));
416 }
417
418 static boolean r300_dsa_alpha_test_enabled(struct r300_dsa_state* dsa)
419 {
420 /* We are interested only in the cases when alpha testing can kill
421 * a fragment. */
422 uint32_t af = dsa->alpha_function;
423
424 return (af & R300_FG_ALPHA_FUNC_ENABLE) &&
425 (af & R300_FG_ALPHA_FUNC_ALWAYS) != R300_FG_ALPHA_FUNC_ALWAYS;
426 }
427
428 static void r300_update_ztop(struct r300_context* r300)
429 {
430 struct r300_ztop_state* ztop_state =
431 (struct r300_ztop_state*)r300->ztop_state.state;
432
433 /* This is important enough that I felt it warranted a comment.
434 *
435 * According to the docs, these are the conditions where ZTOP must be
436 * disabled:
437 * 1) Alpha testing enabled
438 * 2) Texture kill instructions in fragment shader
439 * 3) Chroma key culling enabled
440 * 4) W-buffering enabled
441 *
442 * The docs claim that for the first three cases, if no ZS writes happen,
443 * then ZTOP can be used.
444 *
445 * (3) will never apply since we do not support chroma-keyed operations.
446 * (4) will need to be re-examined (and this comment updated) if/when
447 * Hyper-Z becomes supported.
448 *
449 * Additionally, the following conditions require disabled ZTOP:
450 * 5) Depth writes in fragment shader
451 * 6) Outstanding occlusion queries
452 *
453 * This register causes stalls all the way from SC to CB when changed,
454 * but it is buffered on-chip so it does not hurt to write it if it has
455 * not changed.
456 *
457 * ~C.
458 */
459
460 /* ZS writes */
461 if (r300_dsa_writes_depth_stencil(r300->dsa_state.state) &&
462 (r300_dsa_alpha_test_enabled(r300->dsa_state.state) || /* (1) */
463 r300_fs(r300)->shader->info.uses_kill)) { /* (2) */
464 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
465 } else if (r300_fragment_shader_writes_depth(r300_fs(r300))) { /* (5) */
466 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
467 } else if (r300->query_current) { /* (6) */
468 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
469 } else {
470 ztop_state->z_buffer_top = R300_ZTOP_ENABLE;
471 }
472
473 r300->ztop_state.dirty = TRUE;
474 }
475
476 static void r300_merge_textures_and_samplers(struct r300_context* r300)
477 {
478 struct r300_textures_state *state =
479 (struct r300_textures_state*)r300->textures_state.state;
480 struct r300_texture_sampler_state *texstate;
481 struct r300_sampler_state *sampler;
482 struct r300_sampler_view *view;
483 struct r300_texture *tex;
484 unsigned min_level, max_level, i, size;
485 unsigned count = MIN2(state->sampler_view_count,
486 state->sampler_state_count);
487
488 state->tx_enable = 0;
489 state->count = 0;
490 size = 2;
491
492 for (i = 0; i < count; i++) {
493 if (state->sampler_views[i] && state->sampler_states[i]) {
494 state->tx_enable |= 1 << i;
495
496 view = state->sampler_views[i];
497 tex = r300_texture(view->base.texture);
498 sampler = state->sampler_states[i];
499
500 texstate = &state->regs[i];
501 texstate->format = view->format;
502 texstate->filter0 = sampler->filter0;
503 texstate->filter1 = sampler->filter1;
504 texstate->border_color = sampler->border_color;
505
506 /* to emulate 1D textures through 2D ones correctly */
507 if (tex->b.b.target == PIPE_TEXTURE_1D) {
508 texstate->filter0 &= ~R300_TX_WRAP_T_MASK;
509 texstate->filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
510 }
511
512 if (tex->uses_pitch) {
513 /* NPOT textures don't support mip filter, unfortunately.
514 * This prevents incorrect rendering. */
515 texstate->filter0 &= ~R300_TX_MIN_FILTER_MIP_MASK;
516
517 /* Mask out the mirrored flag. */
518 if (texstate->filter0 & R300_TX_WRAP_S(R300_TX_MIRRORED)) {
519 texstate->filter0 &= ~R300_TX_WRAP_S(R300_TX_MIRRORED);
520 }
521 if (texstate->filter0 & R300_TX_WRAP_T(R300_TX_MIRRORED)) {
522 texstate->filter0 &= ~R300_TX_WRAP_T(R300_TX_MIRRORED);
523 }
524
525 /* Change repeat to clamp-to-edge.
526 * (the repeat bit has a value of 0, no masking needed). */
527 if ((texstate->filter0 & R300_TX_WRAP_S_MASK) ==
528 R300_TX_WRAP_S(R300_TX_REPEAT)) {
529 texstate->filter0 |= R300_TX_WRAP_S(R300_TX_CLAMP_TO_EDGE);
530 }
531 if ((texstate->filter0 & R300_TX_WRAP_T_MASK) ==
532 R300_TX_WRAP_T(R300_TX_REPEAT)) {
533 texstate->filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
534 }
535 } else {
536 /* determine min/max levels */
537 /* the MAX_MIP level is the largest (finest) one */
538 max_level = MIN3(sampler->max_lod + view->base.first_level,
539 tex->b.b.last_level, view->base.last_level);
540 min_level = MIN2(sampler->min_lod + view->base.first_level,
541 max_level);
542 texstate->format.format0 |= R300_TX_NUM_LEVELS(max_level);
543 texstate->filter0 |= R300_TX_MAX_MIP_LEVEL(min_level);
544 }
545
546 texstate->filter0 |= i << 28;
547
548 size += 16;
549 state->count = i+1;
550 }
551 }
552
553 r300->textures_state.size = size;
554
555 /* Pick a fragment shader based on either the texture compare state
556 * or the uses_pitch flag. */
557 if (r300->fs.state && count) {
558 if (r300_pick_fragment_shader(r300)) {
559 r300_mark_fs_code_dirty(r300);
560 }
561 }
562 }
563
564 void r300_update_derived_state(struct r300_context* r300)
565 {
566 if (r300->textures_state.dirty) {
567 r300_merge_textures_and_samplers(r300);
568 }
569
570 if (r300->rs_block_state.dirty) {
571 r300_update_derived_shader_state(r300);
572 }
573
574 if (r300->draw) {
575 memset(&r300->vertex_info, 0, sizeof(struct vertex_info));
576 r300_draw_emit_all_attribs(r300);
577 draw_compute_vertex_size(&r300->vertex_info);
578 r300_swtcl_vertex_psc(r300);
579 }
580
581 r300_update_ztop(r300);
582 }