r300g: atomize texture and sampler states
[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_derived.h"
34 #include "r300_state_inlines.h"
35 #include "r300_vs.h"
36
37 /* r300_state_derived: Various bits of state which are dependent upon
38 * currently bound CSO data. */
39
40 static void r300_draw_emit_attrib(struct r300_context* r300,
41 enum attrib_emit emit,
42 enum interp_mode interp,
43 int index)
44 {
45 struct r300_vertex_shader* vs = r300->vs_state.state;
46 struct tgsi_shader_info* info = &vs->info;
47 int output;
48
49 output = draw_find_shader_output(r300->draw,
50 info->output_semantic_name[index],
51 info->output_semantic_index[index]);
52 draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output);
53 }
54
55 static void r300_draw_emit_all_attribs(struct r300_context* r300)
56 {
57 struct r300_vertex_shader* vs = r300->vs_state.state;
58 struct r300_shader_semantics* vs_outputs = &vs->outputs;
59 int i, gen_count;
60
61 /* Position. */
62 if (vs_outputs->pos != ATTR_UNUSED) {
63 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
64 vs_outputs->pos);
65 } else {
66 assert(0);
67 }
68
69 /* Point size. */
70 if (vs_outputs->psize != ATTR_UNUSED) {
71 r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS,
72 vs_outputs->psize);
73 }
74
75 /* Colors. */
76 for (i = 0; i < ATTR_COLOR_COUNT; i++) {
77 if (vs_outputs->color[i] != ATTR_UNUSED) {
78 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR,
79 vs_outputs->color[i]);
80 }
81 }
82
83 /* XXX Back-face colors. */
84
85 /* Texture coordinates. */
86 gen_count = 0;
87 for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
88 if (vs_outputs->generic[i] != ATTR_UNUSED) {
89 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
90 vs_outputs->generic[i]);
91 gen_count++;
92 }
93 }
94
95 /* Fog coordinates. */
96 if (vs_outputs->fog != ATTR_UNUSED) {
97 r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
98 vs_outputs->fog);
99 gen_count++;
100 }
101
102 /* XXX magic */
103 assert(gen_count <= 8);
104 }
105
106 /* Update the PSC tables. */
107 /* XXX move this function into r300_state.c after TCL-bypass gets removed
108 * XXX because this one is dependent only on vertex elements. */
109 static void r300_vertex_psc(struct r300_context* r300)
110 {
111 struct r300_vertex_shader* vs = r300->vs_state.state;
112 struct r300_vertex_stream_state *vformat =
113 (struct r300_vertex_stream_state*)r300->vertex_stream_state.state;
114 uint16_t type, swizzle;
115 enum pipe_format format;
116 unsigned i;
117 int identity[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
118 int* stream_tab;
119
120 memset(vformat, 0, sizeof(struct r300_vertex_stream_state));
121
122 /* If TCL is bypassed, map vertex streams to equivalent VS output
123 * locations. */
124 if (r300->tcl_bypass) {
125 stream_tab = vs->stream_loc_notcl;
126 } else {
127 stream_tab = identity;
128 }
129
130 /* Vertex shaders have no semantics on their inputs,
131 * so PSC should just route stuff based on the vertex elements,
132 * and not on attrib information. */
133 DBG(r300, DBG_DRAW, "r300: vs expects %d attribs, routing %d elements"
134 " in psc\n",
135 vs->info.num_inputs,
136 r300->vertex_element_count);
137
138 for (i = 0; i < r300->vertex_element_count; i++) {
139 format = r300->vertex_element[i].src_format;
140
141 type = r300_translate_vertex_data_type(format) |
142 (stream_tab[i] << R300_DST_VEC_LOC_SHIFT);
143 swizzle = r300_translate_vertex_data_swizzle(format);
144
145 if (i & 1) {
146 vformat->vap_prog_stream_cntl[i >> 1] |= type << 16;
147 vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
148 } else {
149 vformat->vap_prog_stream_cntl[i >> 1] |= type;
150 vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
151 }
152 }
153
154 assert(i <= 15);
155
156 /* Set the last vector in the PSC. */
157 if (i) {
158 i -= 1;
159 }
160 vformat->vap_prog_stream_cntl[i >> 1] |=
161 (R300_LAST_VEC << (i & 1 ? 16 : 0));
162
163 vformat->count = (i >> 1) + 1;
164 r300->vertex_stream_state.size = (1 + vformat->count) * 2;
165 }
166
167 /* Update the PSC tables for SW TCL, using Draw. */
168 static void r300_swtcl_vertex_psc(struct r300_context* r300)
169 {
170 struct r300_vertex_shader* vs = r300->vs_state.state;
171 struct r300_vertex_stream_state *vformat =
172 (struct r300_vertex_stream_state*)r300->vertex_stream_state.state;
173 struct vertex_info* vinfo = &r300->vertex_info;
174 uint16_t type, swizzle;
175 enum pipe_format format;
176 unsigned i, attrib_count;
177 int* vs_output_tab = vs->stream_loc_notcl;
178
179 memset(vformat, 0, sizeof(struct r300_vertex_stream_state));
180
181 /* For each Draw attribute, route it to the fragment shader according
182 * to the vs_output_tab. */
183 attrib_count = vinfo->num_attribs;
184 DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count);
185 for (i = 0; i < attrib_count; i++) {
186 DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d,"
187 " vs_output_tab %d\n", vinfo->attrib[i].src_index,
188 vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit,
189 vs_output_tab[i]);
190 }
191
192 for (i = 0; i < attrib_count; i++) {
193 /* Make sure we have a proper destination for our attribute. */
194 assert(vs_output_tab[i] != -1);
195
196 format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
197
198 /* Obtain the type of data in this attribute. */
199 type = r300_translate_vertex_data_type(format) |
200 vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
201
202 /* Obtain the swizzle for this attribute. Note that the default
203 * swizzle in the hardware is not XYZW! */
204 swizzle = r300_translate_vertex_data_swizzle(format);
205
206 /* Add the attribute to the PSC table. */
207 if (i & 1) {
208 vformat->vap_prog_stream_cntl[i >> 1] |= type << 16;
209 vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
210 } else {
211 vformat->vap_prog_stream_cntl[i >> 1] |= type;
212 vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
213 }
214 }
215
216 /* Set the last vector in the PSC. */
217 if (i) {
218 i -= 1;
219 }
220 vformat->vap_prog_stream_cntl[i >> 1] |=
221 (R300_LAST_VEC << (i & 1 ? 16 : 0));
222
223 vformat->count = (i >> 1) + 1;
224 r300->vertex_stream_state.size = (1 + vformat->count) * 2;
225 }
226
227 static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr,
228 boolean swizzle_0001)
229 {
230 rs->ip[id] |= R300_RS_COL_PTR(ptr);
231 if (swizzle_0001) {
232 rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_0001);
233 } else {
234 rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA);
235 }
236 rs->inst[id] |= R300_RS_INST_COL_ID(id);
237 }
238
239 static void r300_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset)
240 {
241 rs->inst[id] |= R300_RS_INST_COL_CN_WRITE |
242 R300_RS_INST_COL_ADDR(fp_offset);
243 }
244
245 static void r300_rs_tex(struct r300_rs_block* rs, int id, int ptr,
246 boolean swizzle_X001)
247 {
248 if (swizzle_X001) {
249 rs->ip[id] |= R300_RS_TEX_PTR(ptr*4) |
250 R300_RS_SEL_S(R300_RS_SEL_C0) |
251 R300_RS_SEL_T(R300_RS_SEL_K0) |
252 R300_RS_SEL_R(R300_RS_SEL_K0) |
253 R300_RS_SEL_Q(R300_RS_SEL_K1);
254 } else {
255 rs->ip[id] |= R300_RS_TEX_PTR(ptr*4) |
256 R300_RS_SEL_S(R300_RS_SEL_C0) |
257 R300_RS_SEL_T(R300_RS_SEL_C1) |
258 R300_RS_SEL_R(R300_RS_SEL_C2) |
259 R300_RS_SEL_Q(R300_RS_SEL_C3);
260 }
261 rs->inst[id] |= R300_RS_INST_TEX_ID(id);
262 }
263
264 static void r300_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset)
265 {
266 rs->inst[id] |= R300_RS_INST_TEX_CN_WRITE |
267 R300_RS_INST_TEX_ADDR(fp_offset);
268 }
269
270 static void r500_rs_col(struct r300_rs_block* rs, int id, int ptr,
271 boolean swizzle_0001)
272 {
273 rs->ip[id] |= R500_RS_COL_PTR(ptr);
274 if (swizzle_0001) {
275 rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_0001);
276 } else {
277 rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA);
278 }
279 rs->inst[id] |= R500_RS_INST_COL_ID(id);
280 }
281
282 static void r500_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset)
283 {
284 rs->inst[id] |= R500_RS_INST_COL_CN_WRITE |
285 R500_RS_INST_COL_ADDR(fp_offset);
286 }
287
288 static void r500_rs_tex(struct r300_rs_block* rs, int id, int ptr,
289 boolean swizzle_X001)
290 {
291 int rs_tex_comp = ptr*4;
292
293 if (swizzle_X001) {
294 rs->ip[id] |= R500_RS_SEL_S(rs_tex_comp) |
295 R500_RS_SEL_T(R500_RS_IP_PTR_K0) |
296 R500_RS_SEL_R(R500_RS_IP_PTR_K0) |
297 R500_RS_SEL_Q(R500_RS_IP_PTR_K1);
298 } else {
299 rs->ip[id] |= R500_RS_SEL_S(rs_tex_comp) |
300 R500_RS_SEL_T(rs_tex_comp + 1) |
301 R500_RS_SEL_R(rs_tex_comp + 2) |
302 R500_RS_SEL_Q(rs_tex_comp + 3);
303 }
304 rs->inst[id] |= R500_RS_INST_TEX_ID(id);
305 }
306
307 static void r500_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset)
308 {
309 rs->inst[id] |= R500_RS_INST_TEX_CN_WRITE |
310 R500_RS_INST_TEX_ADDR(fp_offset);
311 }
312
313 /* Set up the RS block.
314 *
315 * This is the part of the chipset that actually does the rasterization
316 * of vertices into fragments. This is also the part of the chipset that
317 * locks up if any part of it is even slightly wrong. */
318 static void r300_update_rs_block(struct r300_context* r300,
319 struct r300_shader_semantics* vs_outputs,
320 struct r300_shader_semantics* fs_inputs)
321 {
322 struct r300_rs_block rs = { { 0 } };
323 int i, col_count = 0, tex_count = 0, fp_offset = 0, count;
324 void (*rX00_rs_col)(struct r300_rs_block*, int, int, boolean);
325 void (*rX00_rs_col_write)(struct r300_rs_block*, int, int);
326 void (*rX00_rs_tex)(struct r300_rs_block*, int, int, boolean);
327 void (*rX00_rs_tex_write)(struct r300_rs_block*, int, int);
328 boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED ||
329 vs_outputs->bcolor[1] != ATTR_UNUSED;
330
331 if (r300_screen(r300->context.screen)->caps->is_r500) {
332 rX00_rs_col = r500_rs_col;
333 rX00_rs_col_write = r500_rs_col_write;
334 rX00_rs_tex = r500_rs_tex;
335 rX00_rs_tex_write = r500_rs_tex_write;
336 } else {
337 rX00_rs_col = r300_rs_col;
338 rX00_rs_col_write = r300_rs_col_write;
339 rX00_rs_tex = r300_rs_tex;
340 rX00_rs_tex_write = r300_rs_tex_write;
341 }
342
343 /* Rasterize colors. */
344 for (i = 0; i < ATTR_COLOR_COUNT; i++) {
345 if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used ||
346 vs_outputs->color[1] != ATTR_UNUSED) {
347 /* Always rasterize if it's written by the VS,
348 * otherwise it locks up. */
349 rX00_rs_col(&rs, col_count, i, FALSE);
350
351 /* Write it to the FS input register if it's used by the FS. */
352 if (fs_inputs->color[i] != ATTR_UNUSED) {
353 rX00_rs_col_write(&rs, col_count, fp_offset);
354 fp_offset++;
355 }
356 col_count++;
357 } else {
358 /* Skip the FS input register, leave it uninitialized. */
359 /* If we try to set it to (0,0,0,1), it will lock up. */
360 if (fs_inputs->color[i] != ATTR_UNUSED) {
361 fp_offset++;
362 }
363 }
364 }
365
366 /* Rasterize texture coordinates. */
367 for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
368 if (vs_outputs->generic[i] != ATTR_UNUSED) {
369 /* Always rasterize if it's written by the VS,
370 * otherwise it locks up. */
371 rX00_rs_tex(&rs, tex_count, tex_count, FALSE);
372
373 /* Write it to the FS input register if it's used by the FS. */
374 if (fs_inputs->generic[i] != ATTR_UNUSED) {
375 rX00_rs_tex_write(&rs, tex_count, fp_offset);
376 fp_offset++;
377 }
378 tex_count++;
379 } else {
380 /* Skip the FS input register, leave it uninitialized. */
381 /* If we try to set it to (0,0,0,1), it will lock up. */
382 if (fs_inputs->generic[i] != ATTR_UNUSED) {
383 fp_offset++;
384 }
385 }
386 }
387
388 /* Rasterize fog coordinates. */
389 if (vs_outputs->fog != ATTR_UNUSED) {
390 /* Always rasterize if it's written by the VS,
391 * otherwise it locks up. */
392 rX00_rs_tex(&rs, tex_count, tex_count, TRUE);
393
394 /* Write it to the FS input register if it's used by the FS. */
395 if (fs_inputs->fog != ATTR_UNUSED) {
396 rX00_rs_tex_write(&rs, tex_count, fp_offset);
397 fp_offset++;
398 }
399 tex_count++;
400 } else {
401 /* Skip the FS input register, leave it uninitialized. */
402 /* If we try to set it to (0,0,0,1), it will lock up. */
403 if (fs_inputs->fog != ATTR_UNUSED) {
404 fp_offset++;
405 }
406 }
407
408 /* Rasterize WPOS. */
409 /* If the FS doesn't need it, it's not written by the VS. */
410 if (fs_inputs->wpos != ATTR_UNUSED) {
411 rX00_rs_tex(&rs, tex_count, tex_count, FALSE);
412 rX00_rs_tex_write(&rs, tex_count, fp_offset);
413
414 fp_offset++;
415 tex_count++;
416 }
417
418 /* Rasterize at least one color, or bad things happen. */
419 if (col_count == 0 && tex_count == 0) {
420 rX00_rs_col(&rs, 0, 0, TRUE);
421 col_count++;
422 }
423
424 rs.count = (tex_count*4) | (col_count << R300_IC_COUNT_SHIFT) |
425 R300_HIRES_EN;
426
427 count = MAX3(col_count, tex_count, 1);
428 rs.inst_count = count - 1;
429
430 /* Now, after all that, see if we actually need to update the state. */
431 if (memcmp(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block))) {
432 memcpy(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block));
433 r300->rs_block_state.size = 5 + count*2;
434 }
435 }
436
437 /* Update the shader-dependant states. */
438 static void r300_update_derived_shader_state(struct r300_context* r300)
439 {
440 struct r300_vertex_shader* vs = r300->vs_state.state;
441 struct r300_screen* r300screen = r300_screen(r300->context.screen);
442 struct r300_vap_output_state *vap_out =
443 (struct r300_vap_output_state*)r300->vap_output_state.state;
444
445 /* XXX Mmm, delicious hax */
446 memset(&r300->vertex_info, 0, sizeof(struct vertex_info));
447 memcpy(vap_out, vs->hwfmt, sizeof(uint)*4);
448
449 r300_update_rs_block(r300, &vs->outputs, &r300->fs->inputs);
450
451 if (r300screen->caps->has_tcl) {
452 r300_vertex_psc(r300);
453 } else {
454 r300_draw_emit_all_attribs(r300);
455 draw_compute_vertex_size(&r300->vertex_info);
456 r300_swtcl_vertex_psc(r300);
457 }
458 }
459
460 static boolean r300_dsa_writes_depth_stencil(struct r300_dsa_state* dsa)
461 {
462 /* We are interested only in the cases when a new depth or stencil value
463 * can be written and changed. */
464
465 /* We might optionally check for [Z func: never] and inspect the stencil
466 * state in a similar fashion, but it's not terribly important. */
467 return (dsa->z_buffer_control & R300_Z_WRITE_ENABLE) ||
468 (dsa->stencil_ref_mask & R300_STENCILWRITEMASK_MASK) ||
469 ((dsa->z_buffer_control & R500_STENCIL_REFMASK_FRONT_BACK) &&
470 (dsa->stencil_ref_bf & R300_STENCILWRITEMASK_MASK));
471 }
472
473 static boolean r300_dsa_alpha_test_enabled(struct r300_dsa_state* dsa)
474 {
475 /* We are interested only in the cases when alpha testing can kill
476 * a fragment. */
477 uint32_t af = dsa->alpha_function;
478
479 return (af & R300_FG_ALPHA_FUNC_ENABLE) &&
480 (af & R300_FG_ALPHA_FUNC_ALWAYS) != R300_FG_ALPHA_FUNC_ALWAYS;
481 }
482
483 static void r300_update_ztop(struct r300_context* r300)
484 {
485 struct r300_ztop_state* ztop_state =
486 (struct r300_ztop_state*)r300->ztop_state.state;
487
488 /* This is important enough that I felt it warranted a comment.
489 *
490 * According to the docs, these are the conditions where ZTOP must be
491 * disabled:
492 * 1) Alpha testing enabled
493 * 2) Texture kill instructions in fragment shader
494 * 3) Chroma key culling enabled
495 * 4) W-buffering enabled
496 *
497 * The docs claim that for the first three cases, if no ZS writes happen,
498 * then ZTOP can be used.
499 *
500 * (3) will never apply since we do not support chroma-keyed operations.
501 * (4) will need to be re-examined (and this comment updated) if/when
502 * Hyper-Z becomes supported.
503 *
504 * Additionally, the following conditions require disabled ZTOP:
505 * 5) Depth writes in fragment shader
506 * 6) Outstanding occlusion queries
507 *
508 * This register causes stalls all the way from SC to CB when changed,
509 * but it is buffered on-chip so it does not hurt to write it if it has
510 * not changed.
511 *
512 * ~C.
513 */
514
515 /* ZS writes */
516 if (r300_dsa_writes_depth_stencil(r300->dsa_state.state) &&
517 (r300_dsa_alpha_test_enabled(r300->dsa_state.state) ||/* (1) */
518 r300->fs->info.uses_kill)) { /* (2) */
519 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
520 } else if (r300_fragment_shader_writes_depth(r300->fs)) { /* (5) */
521 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
522 } else if (r300->query_current) { /* (6) */
523 ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
524 } else {
525 ztop_state->z_buffer_top = R300_ZTOP_ENABLE;
526 }
527
528 r300->ztop_state.dirty = TRUE;
529 }
530
531 static void r300_merge_textures_and_samplers(struct r300_context* r300)
532 {
533 struct r300_textures_state *state =
534 (struct r300_textures_state*)r300->textures_state.state;
535 struct r300_texture_sampler_state *texstate;
536 struct r300_sampler_state *sampler;
537 struct r300_texture *tex;
538 unsigned min_level, max_level, i, size;
539 unsigned count = MIN2(state->texture_count, state->sampler_count);
540
541 state->tx_enable = 0;
542 size = 2;
543
544 for (i = 0; i < count; i++) {
545 if (state->textures[i] && state->sampler_states[i]) {
546 state->tx_enable |= 1 << i;
547
548 tex = state->textures[i];
549 sampler = state->sampler_states[i];
550
551 texstate = &state->regs[i];
552 memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3);
553 texstate->filter[0] = sampler->filter0;
554 texstate->filter[1] = sampler->filter1;
555 texstate->border_color = sampler->border_color;
556 texstate->tile_config = R300_TXO_MACRO_TILE(tex->macrotile) |
557 R300_TXO_MICRO_TILE(tex->microtile);
558
559 /* to emulate 1D textures through 2D ones correctly */
560 if (tex->tex.target == PIPE_TEXTURE_1D) {
561 texstate->filter[0] &= ~R300_TX_WRAP_T_MASK;
562 texstate->filter[0] |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
563 }
564
565 if (tex->is_npot) {
566 /* NPOT textures don't support mip filter, unfortunately.
567 * This prevents incorrect rendering. */
568 texstate->filter[0] &= ~R300_TX_MIN_FILTER_MIP_MASK;
569 } else {
570 /* determine min/max levels */
571 /* the MAX_MIP level is the largest (finest) one */
572 max_level = MIN2(sampler->max_lod, tex->tex.last_level);
573 min_level = MIN2(sampler->min_lod, max_level);
574 texstate->format[0] |= R300_TX_NUM_LEVELS(max_level);
575 texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level);
576 }
577
578 texstate->filter[0] |= i << 28;
579
580 size += 16;
581 state->count = i+1;
582 }
583 }
584
585 r300->textures_state.size = size;
586 }
587
588 void r300_update_derived_state(struct r300_context* r300)
589 {
590 if (r300->rs_block_state.dirty ||
591 r300->vertex_stream_state.dirty || /* XXX put updating this state out of this file */
592 r300->rs_state.dirty) { /* XXX and remove this one (tcl_bypass dependency) */
593 r300_update_derived_shader_state(r300);
594 }
595
596 if (r300->textures_state.dirty) {
597 r300_merge_textures_and_samplers(r300);
598 }
599
600 r300_update_ztop(r300);
601 }