r300g: cleanup the draw functions
[mesa.git] / src / gallium / drivers / r300 / r300_render.c
1 /*
2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 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 /* r300_render: Vertex and index buffer primitive emission. Contains both
25 * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */
26
27 #include "draw/draw_context.h"
28 #include "draw/draw_vbuf.h"
29
30 #include "util/u_inlines.h"
31
32 #include "util/u_format.h"
33 #include "util/u_memory.h"
34 #include "util/u_upload_mgr.h"
35 #include "util/u_prim.h"
36
37 #include "r300_cs.h"
38 #include "r300_context.h"
39 #include "r300_screen_buffer.h"
40 #include "r300_emit.h"
41 #include "r300_reg.h"
42
43 #include <limits.h>
44
45 #define IMMD_DWORDS 32
46
47 static uint32_t r300_translate_primitive(unsigned prim)
48 {
49 switch (prim) {
50 case PIPE_PRIM_POINTS:
51 return R300_VAP_VF_CNTL__PRIM_POINTS;
52 case PIPE_PRIM_LINES:
53 return R300_VAP_VF_CNTL__PRIM_LINES;
54 case PIPE_PRIM_LINE_LOOP:
55 return R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
56 case PIPE_PRIM_LINE_STRIP:
57 return R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
58 case PIPE_PRIM_TRIANGLES:
59 return R300_VAP_VF_CNTL__PRIM_TRIANGLES;
60 case PIPE_PRIM_TRIANGLE_STRIP:
61 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP;
62 case PIPE_PRIM_TRIANGLE_FAN:
63 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN;
64 case PIPE_PRIM_QUADS:
65 return R300_VAP_VF_CNTL__PRIM_QUADS;
66 case PIPE_PRIM_QUAD_STRIP:
67 return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP;
68 case PIPE_PRIM_POLYGON:
69 return R300_VAP_VF_CNTL__PRIM_POLYGON;
70 default:
71 return 0;
72 }
73 }
74
75 static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300,
76 unsigned mode)
77 {
78 struct r300_rs_state* rs = (struct r300_rs_state*)r300->rs_state.state;
79 uint32_t color_control = rs->color_control;
80
81 /* By default (see r300_state.c:r300_create_rs_state) color_control is
82 * initialized to provoking the first vertex.
83 *
84 * Triangle fans must be reduced to the second vertex, not the first, in
85 * Gallium flatshade-first mode, as per the GL spec.
86 * (http://www.opengl.org/registry/specs/ARB/provoking_vertex.txt)
87 *
88 * Quads never provoke correctly in flatshade-first mode. The first
89 * vertex is never considered as provoking, so only the second, third,
90 * and fourth vertices can be selected, and both "third" and "last" modes
91 * select the fourth vertex. This is probably due to D3D lacking quads.
92 *
93 * Similarly, polygons reduce to the first, not the last, vertex, when in
94 * "last" mode, and all other modes start from the second vertex.
95 *
96 * ~ C.
97 */
98
99 if (rs->rs.flatshade_first) {
100 switch (mode) {
101 case PIPE_PRIM_TRIANGLE_FAN:
102 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND;
103 break;
104 case PIPE_PRIM_QUADS:
105 case PIPE_PRIM_QUAD_STRIP:
106 case PIPE_PRIM_POLYGON:
107 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST;
108 break;
109 default:
110 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST;
111 break;
112 }
113 } else {
114 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST;
115 }
116
117 return color_control;
118 }
119
120 void r500_emit_index_bias(struct r300_context *r300, int index_bias)
121 {
122 CS_LOCALS(r300);
123
124 BEGIN_CS(2);
125 OUT_CS_REG(R500_VAP_INDEX_OFFSET,
126 (index_bias & 0xFFFFFF) | (index_bias < 0 ? 1<<24 : 0));
127 END_CS;
128 }
129
130 static void r300_emit_draw_init(struct r300_context *r300, unsigned mode,
131 unsigned min_index, unsigned max_index)
132 {
133 CS_LOCALS(r300);
134
135 BEGIN_CS(5);
136 OUT_CS_REG(R300_GA_COLOR_CONTROL,
137 r300_provoking_vertex_fixes(r300, mode));
138 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2);
139 OUT_CS(max_index);
140 OUT_CS(min_index);
141 END_CS;
142 }
143
144 /* This function splits the index bias value into two parts:
145 * - buffer_offset: the value that can be safely added to buffer offsets
146 * in r300_emit_vertex_arrays (it must yield a positive offset when added to
147 * a vertex buffer offset)
148 * - index_offset: the value that must be manually subtracted from indices
149 * in an index buffer to achieve negative offsets. */
150 static void r300_split_index_bias(struct r300_context *r300, int index_bias,
151 int *buffer_offset, int *index_offset)
152 {
153 struct pipe_vertex_buffer *vb, *vbufs = r300->vbuf_mgr->vertex_buffer;
154 struct pipe_vertex_element *velem = r300->velems->velem;
155 unsigned i, size;
156 int max_neg_bias;
157
158 if (index_bias < 0) {
159 /* See how large index bias we may subtract. We must be careful
160 * here because negative buffer offsets are not allowed
161 * by the DRM API. */
162 max_neg_bias = INT_MAX;
163 for (i = 0; i < r300->velems->count; i++) {
164 vb = &vbufs[velem[i].vertex_buffer_index];
165 size = (vb->buffer_offset + velem[i].src_offset) / vb->stride;
166 max_neg_bias = MIN2(max_neg_bias, size);
167 }
168
169 /* Now set the minimum allowed value. */
170 *buffer_offset = MAX2(-max_neg_bias, index_bias);
171 } else {
172 /* A positive index bias is OK. */
173 *buffer_offset = index_bias;
174 }
175
176 *index_offset = index_bias - *buffer_offset;
177 }
178
179 enum r300_prepare_flags {
180 PREP_FIRST_DRAW = (1 << 0), /* call emit_dirty_state and friends? */
181 PREP_VALIDATE_VBOS = (1 << 1), /* validate VBOs? */
182 PREP_EMIT_AOS = (1 << 2), /* call emit_vertex_arrays? */
183 PREP_EMIT_AOS_SWTCL = (1 << 3), /* call emit_vertex_arrays_swtcl? */
184 PREP_INDEXED = (1 << 4) /* is this draw_elements? */
185 };
186
187 /**
188 * Check if the requested number of dwords is available in the CS and
189 * if not, flush.
190 * \param r300 The context.
191 * \param flags See r300_prepare_flags.
192 * \param cs_dwords The number of dwords to reserve in CS.
193 * \return TRUE if the CS was flushed
194 */
195 static boolean r300_reserve_cs_dwords(struct r300_context *r300,
196 enum r300_prepare_flags flags,
197 unsigned cs_dwords)
198 {
199 boolean flushed = FALSE;
200 boolean first_draw = flags & PREP_FIRST_DRAW;
201 boolean emit_vertex_arrays = flags & PREP_EMIT_AOS;
202 boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_AOS_SWTCL;
203
204 /* Add dirty state, index offset, and AOS. */
205 if (first_draw) {
206 cs_dwords += r300_get_num_dirty_dwords(r300);
207
208 if (r300->screen->caps.index_bias_supported)
209 cs_dwords += 2; /* emit_index_offset */
210
211 if (emit_vertex_arrays)
212 cs_dwords += 55; /* emit_vertex_arrays */
213
214 if (emit_vertex_arrays_swtcl)
215 cs_dwords += 7; /* emit_vertex_arrays_swtcl */
216 }
217
218 cs_dwords += r300_get_num_cs_end_dwords(r300);
219
220 /* Reserve requested CS space. */
221 if (cs_dwords > (R300_MAX_CMDBUF_DWORDS - r300->cs->cdw)) {
222 r300->context.flush(&r300->context, 0, NULL);
223 flushed = TRUE;
224 }
225
226 return flushed;
227 }
228
229 /**
230 * Validate buffers and emit dirty state.
231 * \param r300 The context.
232 * \param flags See r300_prepare_flags.
233 * \param index_buffer The index buffer to validate. The parameter may be NULL.
234 * \param buffer_offset The offset passed to emit_vertex_arrays.
235 * \param index_bias The index bias to emit.
236 * \return TRUE if rendering should be skipped
237 */
238 static boolean r300_emit_states(struct r300_context *r300,
239 enum r300_prepare_flags flags,
240 struct pipe_resource *index_buffer,
241 int buffer_offset,
242 int index_bias,
243 boolean user_buffers)
244 {
245 boolean first_draw = flags & PREP_FIRST_DRAW;
246 boolean emit_vertex_arrays = flags & PREP_EMIT_AOS;
247 boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_AOS_SWTCL;
248 boolean indexed = flags & PREP_INDEXED;
249 boolean validate_vbos = flags & PREP_VALIDATE_VBOS;
250
251 /* Validate buffers and emit dirty state if needed. */
252 if (first_draw) {
253 if (r300->validate_buffers) {
254 if (!r300_emit_buffer_validate(r300, validate_vbos,
255 index_buffer)) {
256 fprintf(stderr, "r300: CS space validation failed. "
257 "(not enough memory?) Skipping rendering.\n");
258 return FALSE;
259 }
260
261 /* Consider the validation done only if everything was validated. */
262 if (validate_vbos) {
263 r300->validate_buffers = FALSE;
264 if (user_buffers)
265 r300->upload_vb_validated = TRUE;
266 if (r300->index_buffer.buffer &&
267 r300_resource(r300->index_buffer.buffer)->b.user_ptr) {
268 r300->upload_ib_validated = TRUE;
269 }
270 }
271 }
272
273 r300_emit_dirty_state(r300);
274 if (r300->screen->caps.index_bias_supported) {
275 if (r300->screen->caps.has_tcl)
276 r500_emit_index_bias(r300, index_bias);
277 else
278 r500_emit_index_bias(r300, 0);
279 }
280
281 if (emit_vertex_arrays &&
282 (r300->vertex_arrays_dirty ||
283 r300->vertex_arrays_indexed != indexed ||
284 r300->vertex_arrays_offset != buffer_offset)) {
285 r300_emit_vertex_arrays(r300, buffer_offset, indexed);
286
287 r300->vertex_arrays_dirty = FALSE;
288 r300->vertex_arrays_indexed = indexed;
289 r300->vertex_arrays_offset = buffer_offset;
290 }
291
292 if (emit_vertex_arrays_swtcl)
293 r300_emit_vertex_arrays_swtcl(r300, indexed);
294 }
295
296 return TRUE;
297 }
298
299 /**
300 * Check if the requested number of dwords is available in the CS and
301 * if not, flush. Then validate buffers and emit dirty state.
302 * \param r300 The context.
303 * \param flags See r300_prepare_flags.
304 * \param index_buffer The index buffer to validate. The parameter may be NULL.
305 * \param cs_dwords The number of dwords to reserve in CS.
306 * \param buffer_offset The offset passed to emit_vertex_arrays.
307 * \param index_bias The index bias to emit.
308 * \return TRUE if rendering should be skipped
309 */
310 static boolean r300_prepare_for_rendering(struct r300_context *r300,
311 enum r300_prepare_flags flags,
312 struct pipe_resource *index_buffer,
313 unsigned cs_dwords,
314 int buffer_offset,
315 int index_bias,
316 boolean user_buffers)
317 {
318 if (r300_reserve_cs_dwords(r300, flags, cs_dwords))
319 flags |= PREP_FIRST_DRAW;
320
321 return r300_emit_states(r300, flags, index_buffer, buffer_offset,
322 index_bias, user_buffers);
323 }
324
325 static boolean immd_is_good_idea(struct r300_context *r300,
326 unsigned count)
327 {
328 struct pipe_vertex_element* velem;
329 struct pipe_resource *buf;
330 boolean checked[PIPE_MAX_ATTRIBS] = {0};
331 unsigned vertex_element_count = r300->velems->count;
332 unsigned i, vbi;
333
334 if (DBG_ON(r300, DBG_NO_IMMD)) {
335 return FALSE;
336 }
337
338 if (r300->draw) {
339 return FALSE;
340 }
341
342 if (count * r300->velems->vertex_size_dwords > IMMD_DWORDS) {
343 return FALSE;
344 }
345
346 /* We shouldn't map buffers referenced by CS, busy buffers,
347 * and ones placed in VRAM. */
348 for (i = 0; i < vertex_element_count; i++) {
349 velem = &r300->velems->velem[i];
350 vbi = velem->vertex_buffer_index;
351
352 if (!checked[vbi]) {
353 buf = r300->vbuf_mgr->real_vertex_buffer[vbi];
354
355 if ((r300_resource(buf)->domain != R300_DOMAIN_GTT)) {
356 return FALSE;
357 }
358
359 checked[vbi] = TRUE;
360 }
361 }
362 return TRUE;
363 }
364
365 /*****************************************************************************
366 * The HWTCL draw functions. *
367 ****************************************************************************/
368
369 static void r300_draw_arrays_immediate(struct r300_context *r300,
370 unsigned mode, unsigned start,
371 unsigned count)
372 {
373 struct pipe_vertex_element* velem;
374 struct pipe_vertex_buffer* vbuf;
375 unsigned vertex_element_count = r300->velems->count;
376 unsigned i, v, vbi;
377
378 /* Size of the vertex, in dwords. */
379 unsigned vertex_size = r300->velems->vertex_size_dwords;
380
381 /* The number of dwords for this draw operation. */
382 unsigned dwords = 4 + count * vertex_size;
383
384 /* Size of the vertex element, in dwords. */
385 unsigned size[PIPE_MAX_ATTRIBS];
386
387 /* Stride to the same attrib in the next vertex in the vertex buffer,
388 * in dwords. */
389 unsigned stride[PIPE_MAX_ATTRIBS];
390
391 /* Mapped vertex buffers. */
392 uint32_t* map[PIPE_MAX_ATTRIBS];
393 uint32_t* mapelem[PIPE_MAX_ATTRIBS];
394 struct pipe_transfer* transfer[PIPE_MAX_ATTRIBS] = {0};
395
396 CS_LOCALS(r300);
397
398 if (!r300_prepare_for_rendering(r300, PREP_FIRST_DRAW, NULL, dwords, 0, 0,
399 FALSE))
400 return;
401
402 /* Calculate the vertex size, offsets, strides etc. and map the buffers. */
403 for (i = 0; i < vertex_element_count; i++) {
404 velem = &r300->velems->velem[i];
405 size[i] = r300->velems->format_size[i] / 4;
406 vbi = velem->vertex_buffer_index;
407 vbuf = &r300->vbuf_mgr->vertex_buffer[vbi];
408 stride[i] = vbuf->stride / 4;
409
410 /* Map the buffer. */
411 if (!transfer[vbi]) {
412 map[vbi] = (uint32_t*)pipe_buffer_map(&r300->context,
413 r300->vbuf_mgr->real_vertex_buffer[vbi],
414 PIPE_TRANSFER_READ |
415 PIPE_TRANSFER_UNSYNCHRONIZED,
416 &transfer[vbi]);
417 map[vbi] += (vbuf->buffer_offset / 4) + stride[i] * start;
418 }
419 mapelem[i] = map[vbi] + (velem->src_offset / 4);
420 }
421
422 r300_emit_draw_init(r300, mode, 0, count-1);
423
424 BEGIN_CS(dwords);
425 OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size);
426 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, count * vertex_size);
427 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (count << 16) |
428 r300_translate_primitive(mode));
429
430 /* Emit vertices. */
431 for (v = 0; v < count; v++) {
432 for (i = 0; i < vertex_element_count; i++) {
433 OUT_CS_TABLE(&mapelem[i][stride[i] * v], size[i]);
434 }
435 }
436 END_CS;
437
438 /* Unmap buffers. */
439 for (i = 0; i < vertex_element_count; i++) {
440 vbi = r300->velems->velem[i].vertex_buffer_index;
441
442 if (transfer[vbi]) {
443 pipe_buffer_unmap(&r300->context, transfer[vbi]);
444 transfer[vbi] = NULL;
445 }
446 }
447 }
448
449 static void r300_emit_draw_arrays(struct r300_context *r300,
450 unsigned mode,
451 unsigned count)
452 {
453 boolean alt_num_verts = count > 65535;
454 CS_LOCALS(r300);
455
456 if (count >= (1 << 24)) {
457 fprintf(stderr, "r300: Got a huge number of vertices: %i, "
458 "refusing to render.\n", count);
459 return;
460 }
461
462 r300_emit_draw_init(r300, mode, 0, count-1);
463
464 BEGIN_CS(2 + (alt_num_verts ? 2 : 0));
465 if (alt_num_verts) {
466 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
467 }
468 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
469 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
470 r300_translate_primitive(mode) |
471 (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
472 END_CS;
473 }
474
475 static void r300_emit_draw_elements(struct r300_context *r300,
476 struct pipe_resource* indexBuffer,
477 unsigned indexSize,
478 unsigned minIndex,
479 unsigned maxIndex,
480 unsigned mode,
481 unsigned start,
482 unsigned count,
483 uint16_t *imm_indices3)
484 {
485 uint32_t count_dwords, offset_dwords;
486 boolean alt_num_verts = count > 65535;
487 CS_LOCALS(r300);
488
489 if (count >= (1 << 24) || maxIndex >= (1 << 24)) {
490 fprintf(stderr, "r300: Got a huge number of vertices: %i, "
491 "refusing to render (maxIndex: %i).\n", count, maxIndex);
492 return;
493 }
494
495 DBG(r300, DBG_DRAW, "r300: Indexbuf of %u indices, min %u max %u\n",
496 count, minIndex, maxIndex);
497
498 r300_emit_draw_init(r300, mode, minIndex, maxIndex);
499
500 /* If start is odd, render the first triangle with indices embedded
501 * in the command stream. This will increase start by 3 and make it
502 * even. We can then proceed without a fallback. */
503 if (indexSize == 2 && (start & 1) &&
504 mode == PIPE_PRIM_TRIANGLES) {
505 BEGIN_CS(4);
506 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 2);
507 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (3 << 16) |
508 R300_VAP_VF_CNTL__PRIM_TRIANGLES);
509 OUT_CS(imm_indices3[1] << 16 | imm_indices3[0]);
510 OUT_CS(imm_indices3[2]);
511 END_CS;
512
513 start += 3;
514 count -= 3;
515 if (!count)
516 return;
517 }
518
519 offset_dwords = indexSize * start / sizeof(uint32_t);
520
521 BEGIN_CS(8 + (alt_num_verts ? 2 : 0));
522 if (alt_num_verts) {
523 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
524 }
525 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0);
526 if (indexSize == 4) {
527 count_dwords = count;
528 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
529 R300_VAP_VF_CNTL__INDEX_SIZE_32bit |
530 r300_translate_primitive(mode) |
531 (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
532 } else {
533 count_dwords = (count + 1) / 2;
534 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
535 r300_translate_primitive(mode) |
536 (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
537 }
538
539 OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2);
540 OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) |
541 (0 << R300_INDX_BUFFER_SKIP_SHIFT));
542 OUT_CS(offset_dwords << 2);
543 OUT_CS(count_dwords);
544 OUT_CS_RELOC(r300_resource(indexBuffer));
545 END_CS;
546 }
547
548 static void r300_draw_elements(struct r300_context *r300, int indexBias,
549 unsigned minIndex, unsigned maxIndex,
550 unsigned mode, unsigned start, unsigned count,
551 boolean user_buffers)
552 {
553 struct pipe_resource *indexBuffer = r300->index_buffer.buffer;
554 unsigned indexSize = r300->index_buffer.index_size;
555 struct pipe_resource* orgIndexBuffer = indexBuffer;
556 boolean alt_num_verts = r300->screen->caps.is_r500 &&
557 count > 65536 &&
558 r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0);
559 unsigned short_count;
560 int buffer_offset = 0, index_offset = 0; /* for index bias emulation */
561 uint16_t indices3[3];
562
563 if (indexBias && !r300->screen->caps.index_bias_supported) {
564 r300_split_index_bias(r300, indexBias, &buffer_offset, &index_offset);
565 }
566
567 r300_translate_index_buffer(r300, &indexBuffer, &indexSize, index_offset,
568 &start, count);
569
570 /* Fallback for misaligned ushort indices. */
571 if (indexSize == 2 && (start & 1) &&
572 !r300_resource(indexBuffer)->b.user_ptr) {
573 struct pipe_transfer *transfer;
574
575 uint16_t *ptr = pipe_buffer_map(&r300->context, indexBuffer,
576 PIPE_TRANSFER_READ |
577 PIPE_TRANSFER_UNSYNCHRONIZED,
578 &transfer);
579
580 if (mode == PIPE_PRIM_TRIANGLES) {
581 memcpy(indices3, ptr + start, 6);
582 } else {
583 /* Copy the mapped index buffer directly to the upload buffer.
584 * The start index will be aligned simply from the fact that
585 * every sub-buffer in the upload buffer is aligned. */
586 r300_upload_index_buffer(r300, &indexBuffer, indexSize, &start,
587 count, (uint8_t*)ptr);
588 }
589 pipe_buffer_unmap(&r300->context, transfer);
590 } else {
591 if (r300_resource(indexBuffer)->b.user_ptr)
592 r300_upload_index_buffer(r300, &indexBuffer, indexSize,
593 &start, count,
594 r300_resource(indexBuffer)->b.user_ptr);
595 }
596
597 /* 19 dwords for emit_draw_elements. Give up if the function fails. */
598 if (!r300_prepare_for_rendering(r300,
599 PREP_FIRST_DRAW | PREP_VALIDATE_VBOS | PREP_EMIT_AOS |
600 PREP_INDEXED, indexBuffer, 19, buffer_offset, indexBias,
601 user_buffers))
602 goto done;
603
604 if (alt_num_verts || count <= 65535) {
605 r300_emit_draw_elements(r300, indexBuffer, indexSize,
606 minIndex, maxIndex, mode, start, count, indices3);
607 } else {
608 do {
609 if (indexSize == 2 && (start & 1))
610 short_count = MIN2(count, 65535);
611 else
612 short_count = MIN2(count, 65534);
613
614 r300_emit_draw_elements(r300, indexBuffer, indexSize,
615 minIndex, maxIndex,
616 mode, start, short_count, indices3);
617
618 start += short_count;
619 count -= short_count;
620
621 /* 15 dwords for emit_draw_elements */
622 if (count) {
623 if (!r300_prepare_for_rendering(r300,
624 PREP_VALIDATE_VBOS | PREP_EMIT_AOS | PREP_INDEXED,
625 indexBuffer, 19, buffer_offset, indexBias, user_buffers))
626 goto done;
627 }
628 } while (count);
629 }
630
631 done:
632 if (indexBuffer != orgIndexBuffer) {
633 pipe_resource_reference( &indexBuffer, NULL );
634 }
635 }
636
637 static void r300_draw_arrays(struct r300_context *r300, unsigned mode,
638 unsigned start, unsigned count,
639 boolean user_buffers)
640 {
641 boolean alt_num_verts = r300->screen->caps.is_r500 &&
642 count > 65536 &&
643 r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0);
644 unsigned short_count;
645
646 /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
647 if (!r300_prepare_for_rendering(r300,
648 PREP_FIRST_DRAW | PREP_VALIDATE_VBOS | PREP_EMIT_AOS,
649 NULL, 9, start, 0, user_buffers))
650 return;
651
652 if (alt_num_verts || count <= 65535) {
653 r300_emit_draw_arrays(r300, mode, count);
654 } else {
655 do {
656 short_count = MIN2(count, 65535);
657 r300_emit_draw_arrays(r300, mode, short_count);
658
659 start += short_count;
660 count -= short_count;
661
662 /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
663 if (count) {
664 if (!r300_prepare_for_rendering(r300,
665 PREP_VALIDATE_VBOS | PREP_EMIT_AOS, NULL, 9,
666 start, 0, user_buffers))
667 return;
668 }
669 } while (count);
670 }
671 }
672
673 static void r300_draw_vbo(struct pipe_context* pipe,
674 const struct pipe_draw_info *info)
675 {
676 struct r300_context* r300 = r300_context(pipe);
677 unsigned count = info->count;
678 boolean buffers_updated, uploader_flushed;
679 boolean indexed = info->indexed && r300->index_buffer.buffer;
680 unsigned start_indexed = info->start + r300->index_buffer.offset;
681 int max_index = MIN2(r300->vbuf_mgr->max_index, info->max_index);
682
683 if (r300->skip_rendering ||
684 !u_trim_pipe_prim(info->mode, &count)) {
685 return;
686 }
687
688 /* Start the vbuf manager and update buffers if needed. */
689 u_vbuf_mgr_draw_begin(r300->vbuf_mgr, info,
690 &buffers_updated, &uploader_flushed);
691 if (buffers_updated) {
692 r300->vertex_arrays_dirty = TRUE;
693
694 if (uploader_flushed || !r300->upload_vb_validated) {
695 r300->upload_vb_validated = FALSE;
696 r300->validate_buffers = TRUE;
697 }
698 } else {
699 r300->upload_vb_validated = FALSE;
700 }
701
702 /* Draw. */
703 r300_update_derived_state(r300);
704
705 if (indexed) {
706 r300_draw_elements(r300, info->index_bias, info->min_index,
707 max_index, info->mode, start_indexed, count,
708 buffers_updated);
709 } else {
710 if (immd_is_good_idea(r300, count)) {
711 r300_draw_arrays_immediate(r300, info->mode, info->start, count);
712 } else {
713 r300_draw_arrays(r300, info->mode, info->start, count,
714 buffers_updated);
715 }
716 }
717
718 u_vbuf_mgr_draw_end(r300->vbuf_mgr);
719 }
720
721 /****************************************************************************
722 * The rest of this file is for SW TCL rendering only. Please be polite and *
723 * keep these functions separated so that they are easier to locate. ~C. *
724 ***************************************************************************/
725
726 /* SW TCL elements, using Draw. */
727 static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
728 const struct pipe_draw_info *info)
729 {
730 struct r300_context* r300 = r300_context(pipe);
731 struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
732 struct pipe_transfer *ib_transfer = NULL;
733 unsigned count = info->count;
734 int i;
735 void *indices = NULL;
736 boolean indexed = info->indexed && r300->index_buffer.buffer;
737
738 if (r300->skip_rendering) {
739 return;
740 }
741
742 if (!u_trim_pipe_prim(info->mode, &count)) {
743 return;
744 }
745
746 r300_update_derived_state(r300);
747
748 r300_reserve_cs_dwords(r300,
749 PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL |
750 (indexed ? PREP_INDEXED : 0),
751 indexed ? 256 : 6);
752
753 for (i = 0; i < r300->vbuf_mgr->nr_vertex_buffers; i++) {
754 if (r300->vbuf_mgr->vertex_buffer[i].buffer) {
755 void *buf = pipe_buffer_map(pipe,
756 r300->vbuf_mgr->vertex_buffer[i].buffer,
757 PIPE_TRANSFER_READ |
758 PIPE_TRANSFER_UNSYNCHRONIZED,
759 &vb_transfer[i]);
760 draw_set_mapped_vertex_buffer(r300->draw, i, buf);
761 }
762 }
763
764 if (indexed) {
765 indices = pipe_buffer_map(pipe, r300->index_buffer.buffer,
766 PIPE_TRANSFER_READ |
767 PIPE_TRANSFER_UNSYNCHRONIZED, &ib_transfer);
768 }
769
770 draw_set_mapped_index_buffer(r300->draw, indices);
771
772 r300->draw_vbo_locked = TRUE;
773 r300->draw_first_emitted = FALSE;
774 draw_vbo(r300->draw, info);
775 draw_flush(r300->draw);
776 r300->draw_vbo_locked = FALSE;
777
778 for (i = 0; i < r300->vbuf_mgr->nr_vertex_buffers; i++) {
779 if (r300->vbuf_mgr->vertex_buffer[i].buffer) {
780 pipe_buffer_unmap(pipe, vb_transfer[i]);
781 draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
782 }
783 }
784
785 if (indexed) {
786 pipe_buffer_unmap(pipe, ib_transfer);
787 draw_set_mapped_index_buffer(r300->draw, NULL);
788 }
789 }
790
791 /* Object for rendering using Draw. */
792 struct r300_render {
793 /* Parent class */
794 struct vbuf_render base;
795
796 /* Pipe context */
797 struct r300_context* r300;
798
799 /* Vertex information */
800 size_t vertex_size;
801 unsigned prim;
802 unsigned hwprim;
803
804 /* VBO */
805 size_t vbo_max_used;
806 void * vbo_ptr;
807
808 struct pipe_transfer *vbo_transfer;
809 };
810
811 static INLINE struct r300_render*
812 r300_render(struct vbuf_render* render)
813 {
814 return (struct r300_render*)render;
815 }
816
817 static const struct vertex_info*
818 r300_render_get_vertex_info(struct vbuf_render* render)
819 {
820 struct r300_render* r300render = r300_render(render);
821 struct r300_context* r300 = r300render->r300;
822
823 return &r300->vertex_info;
824 }
825
826 static boolean r300_render_allocate_vertices(struct vbuf_render* render,
827 ushort vertex_size,
828 ushort count)
829 {
830 struct r300_render* r300render = r300_render(render);
831 struct r300_context* r300 = r300render->r300;
832 struct pipe_screen* screen = r300->context.screen;
833 size_t size = (size_t)vertex_size * (size_t)count;
834
835 DBG(r300, DBG_DRAW, "r300: render_allocate_vertices (size: %d)\n", size);
836
837 if (size + r300->draw_vbo_offset > r300->draw_vbo_size)
838 {
839 pipe_resource_reference(&r300->vbo, NULL);
840 r300->vbo = pipe_buffer_create(screen,
841 PIPE_BIND_VERTEX_BUFFER,
842 R300_MAX_DRAW_VBO_SIZE);
843 r300->draw_vbo_offset = 0;
844 r300->draw_vbo_size = R300_MAX_DRAW_VBO_SIZE;
845 r300->validate_buffers = TRUE;
846 }
847
848 r300render->vertex_size = vertex_size;
849
850 return (r300->vbo) ? TRUE : FALSE;
851 }
852
853 static void* r300_render_map_vertices(struct vbuf_render* render)
854 {
855 struct r300_render* r300render = r300_render(render);
856 struct r300_context* r300 = r300render->r300;
857
858 assert(!r300render->vbo_transfer);
859
860 DBG(r300, DBG_DRAW, "r300: render_map_vertices\n");
861
862 r300render->vbo_ptr = pipe_buffer_map(&r300render->r300->context,
863 r300->vbo,
864 PIPE_TRANSFER_WRITE |
865 PIPE_TRANSFER_UNSYNCHRONIZED,
866 &r300render->vbo_transfer);
867
868 assert(r300render->vbo_ptr);
869
870 return ((uint8_t*)r300render->vbo_ptr + r300->draw_vbo_offset);
871 }
872
873 static void r300_render_unmap_vertices(struct vbuf_render* render,
874 ushort min,
875 ushort max)
876 {
877 struct r300_render* r300render = r300_render(render);
878 struct pipe_context* context = &r300render->r300->context;
879 struct r300_context* r300 = r300render->r300;
880
881 assert(r300render->vbo_transfer);
882
883 DBG(r300, DBG_DRAW, "r300: render_unmap_vertices\n");
884
885 r300render->vbo_max_used = MAX2(r300render->vbo_max_used,
886 r300render->vertex_size * (max + 1));
887 pipe_buffer_unmap(context, r300render->vbo_transfer);
888
889 r300render->vbo_transfer = NULL;
890 }
891
892 static void r300_render_release_vertices(struct vbuf_render* render)
893 {
894 struct r300_render* r300render = r300_render(render);
895 struct r300_context* r300 = r300render->r300;
896
897 DBG(r300, DBG_DRAW, "r300: render_release_vertices\n");
898
899 r300->draw_vbo_offset += r300render->vbo_max_used;
900 r300render->vbo_max_used = 0;
901 }
902
903 static boolean r300_render_set_primitive(struct vbuf_render* render,
904 unsigned prim)
905 {
906 struct r300_render* r300render = r300_render(render);
907
908 r300render->prim = prim;
909 r300render->hwprim = r300_translate_primitive(prim);
910
911 return TRUE;
912 }
913
914 static void r300_render_draw_arrays(struct vbuf_render* render,
915 unsigned start,
916 unsigned count)
917 {
918 struct r300_render* r300render = r300_render(render);
919 struct r300_context* r300 = r300render->r300;
920 uint8_t* ptr;
921 unsigned i;
922 unsigned dwords = 6;
923
924 CS_LOCALS(r300);
925 (void) i; (void) ptr;
926
927 DBG(r300, DBG_DRAW, "r300: render_draw_arrays (count: %d)\n", count);
928
929 if (r300->draw_first_emitted) {
930 if (!r300_prepare_for_rendering(r300,
931 PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL,
932 NULL, dwords, 0, 0, FALSE))
933 return;
934 } else {
935 if (!r300_emit_states(r300,
936 PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL,
937 NULL, 0, 0, FALSE))
938 return;
939 }
940
941 BEGIN_CS(dwords);
942 OUT_CS_REG(R300_GA_COLOR_CONTROL,
943 r300_provoking_vertex_fixes(r300, r300render->prim));
944 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
945 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
946 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
947 r300render->hwprim);
948 END_CS;
949
950 r300->draw_first_emitted = TRUE;
951 }
952
953 static void r300_render_draw_elements(struct vbuf_render* render,
954 const ushort* indices,
955 uint count)
956 {
957 struct r300_render* r300render = r300_render(render);
958 struct r300_context* r300 = r300render->r300;
959 int i;
960 unsigned end_cs_dwords;
961 unsigned max_index = (r300->draw_vbo_size - r300->draw_vbo_offset) /
962 (r300render->r300->vertex_info.size * 4) - 1;
963 unsigned short_count;
964 unsigned free_dwords;
965
966 CS_LOCALS(r300);
967 DBG(r300, DBG_DRAW, "r300: render_draw_elements (count: %d)\n", count);
968
969 if (r300->draw_first_emitted) {
970 if (!r300_prepare_for_rendering(r300,
971 PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
972 NULL, 256, 0, 0, FALSE))
973 return;
974 } else {
975 if (!r300_emit_states(r300,
976 PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
977 NULL, 0, 0, FALSE))
978 return;
979 }
980
981 /* Below we manage the CS space manually because there may be more
982 * indices than it can fit in CS. */
983
984 end_cs_dwords = r300_get_num_cs_end_dwords(r300);
985
986 while (count) {
987 free_dwords = R300_MAX_CMDBUF_DWORDS - r300->cs->cdw;
988
989 short_count = MIN2(count, (free_dwords - end_cs_dwords - 6) * 2);
990
991 BEGIN_CS(6 + (short_count+1)/2);
992 OUT_CS_REG(R300_GA_COLOR_CONTROL,
993 r300_provoking_vertex_fixes(r300, r300render->prim));
994 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max_index);
995 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (short_count+1)/2);
996 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (short_count << 16) |
997 r300render->hwprim);
998 for (i = 0; i < short_count-1; i += 2) {
999 OUT_CS(indices[i+1] << 16 | indices[i]);
1000 }
1001 if (short_count % 2) {
1002 OUT_CS(indices[short_count-1]);
1003 }
1004 END_CS;
1005
1006 /* OK now subtract the emitted indices and see if we need to emit
1007 * another draw packet. */
1008 indices += short_count;
1009 count -= short_count;
1010
1011 if (count) {
1012 if (!r300_prepare_for_rendering(r300,
1013 PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
1014 NULL, 256, 0, 0, FALSE))
1015 return;
1016
1017 end_cs_dwords = r300_get_num_cs_end_dwords(r300);
1018 }
1019 }
1020
1021 r300->draw_first_emitted = TRUE;
1022 }
1023
1024 static void r300_render_destroy(struct vbuf_render* render)
1025 {
1026 FREE(render);
1027 }
1028
1029 static struct vbuf_render* r300_render_create(struct r300_context* r300)
1030 {
1031 struct r300_render* r300render = CALLOC_STRUCT(r300_render);
1032
1033 r300render->r300 = r300;
1034
1035 r300render->base.max_vertex_buffer_bytes = 1024 * 1024;
1036 r300render->base.max_indices = 16 * 1024;
1037
1038 r300render->base.get_vertex_info = r300_render_get_vertex_info;
1039 r300render->base.allocate_vertices = r300_render_allocate_vertices;
1040 r300render->base.map_vertices = r300_render_map_vertices;
1041 r300render->base.unmap_vertices = r300_render_unmap_vertices;
1042 r300render->base.set_primitive = r300_render_set_primitive;
1043 r300render->base.draw_elements = r300_render_draw_elements;
1044 r300render->base.draw_arrays = r300_render_draw_arrays;
1045 r300render->base.release_vertices = r300_render_release_vertices;
1046 r300render->base.destroy = r300_render_destroy;
1047
1048 return &r300render->base;
1049 }
1050
1051 struct draw_stage* r300_draw_stage(struct r300_context* r300)
1052 {
1053 struct vbuf_render* render;
1054 struct draw_stage* stage;
1055
1056 render = r300_render_create(r300);
1057
1058 if (!render) {
1059 return NULL;
1060 }
1061
1062 stage = draw_vbuf_stage(r300->draw, render);
1063
1064 if (!stage) {
1065 render->destroy(render);
1066 return NULL;
1067 }
1068
1069 draw_set_render(r300->draw, render);
1070
1071 return stage;
1072 }
1073
1074 void r300_draw_flush_vbuf(struct r300_context *r300)
1075 {
1076 pipe_resource_reference(&r300->vbo, NULL);
1077 r300->draw_vbo_size = 0;
1078 }
1079
1080 /****************************************************************************
1081 * End of SW TCL functions *
1082 ***************************************************************************/
1083
1084 /* This functions is used to draw a rectangle for the blitter module.
1085 *
1086 * If we rendered a quad, the pixels on the main diagonal
1087 * would be computed and stored twice, which makes the clear/copy codepaths
1088 * somewhat inefficient. Instead we use a rectangular point sprite. */
1089 static void r300_blitter_draw_rectangle(struct blitter_context *blitter,
1090 unsigned x1, unsigned y1,
1091 unsigned x2, unsigned y2,
1092 float depth,
1093 enum blitter_attrib_type type,
1094 const float attrib[4])
1095 {
1096 struct r300_context *r300 = r300_context(util_blitter_get_pipe(blitter));
1097 unsigned last_sprite_coord_enable = r300->sprite_coord_enable;
1098 unsigned width = x2 - x1;
1099 unsigned height = y2 - y1;
1100 unsigned vertex_size =
1101 type == UTIL_BLITTER_ATTRIB_COLOR || !r300->draw ? 8 : 4;
1102 unsigned dwords = 13 + vertex_size +
1103 (type == UTIL_BLITTER_ATTRIB_TEXCOORD ? 7 : 0);
1104 const float zeros[4] = {0, 0, 0, 0};
1105 CS_LOCALS(r300);
1106
1107 r300->context.set_vertex_buffers(&r300->context, 0, NULL);
1108
1109 if (type == UTIL_BLITTER_ATTRIB_TEXCOORD)
1110 r300->sprite_coord_enable = 1;
1111
1112 r300_update_derived_state(r300);
1113
1114 /* Mark some states we don't care about as non-dirty. */
1115 r300->clip_state.dirty = FALSE;
1116 r300->viewport_state.dirty = FALSE;
1117
1118 if (!r300_prepare_for_rendering(r300, PREP_FIRST_DRAW, NULL, dwords, 0, 0,
1119 FALSE))
1120 goto done;
1121
1122 DBG(r300, DBG_DRAW, "r300: draw_rectangle\n");
1123
1124 BEGIN_CS(dwords);
1125 /* Set up GA. */
1126 OUT_CS_REG(R300_GA_POINT_SIZE, (height * 6) | ((width * 6) << 16));
1127
1128 if (type == UTIL_BLITTER_ATTRIB_TEXCOORD) {
1129 /* Set up the GA to generate texcoords. */
1130 OUT_CS_REG(R300_GB_ENABLE, R300_GB_POINT_STUFF_ENABLE |
1131 (R300_GB_TEX_STR << R300_GB_TEX0_SOURCE_SHIFT));
1132 OUT_CS_REG_SEQ(R300_GA_POINT_S0, 4);
1133 OUT_CS_32F(attrib[0]);
1134 OUT_CS_32F(attrib[3]);
1135 OUT_CS_32F(attrib[2]);
1136 OUT_CS_32F(attrib[1]);
1137 }
1138
1139 /* Set up VAP controls. */
1140 OUT_CS_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE);
1141 OUT_CS_REG(R300_VAP_VTE_CNTL, R300_VTX_XY_FMT | R300_VTX_Z_FMT);
1142 OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size);
1143 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2);
1144 OUT_CS(1);
1145 OUT_CS(0);
1146
1147 /* Draw. */
1148 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, vertex_size);
1149 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (1 << 16) |
1150 R300_VAP_VF_CNTL__PRIM_POINTS);
1151
1152 OUT_CS_32F(x1 + width * 0.5f);
1153 OUT_CS_32F(y1 + height * 0.5f);
1154 OUT_CS_32F(depth);
1155 OUT_CS_32F(1);
1156
1157 if (vertex_size == 8) {
1158 if (!attrib)
1159 attrib = zeros;
1160 OUT_CS_TABLE(attrib, 4);
1161 }
1162 END_CS;
1163
1164 done:
1165 /* Restore the state. */
1166 r300_mark_atom_dirty(r300, &r300->clip_state);
1167 r300_mark_atom_dirty(r300, &r300->rs_state);
1168 r300_mark_atom_dirty(r300, &r300->viewport_state);
1169
1170 r300->sprite_coord_enable = last_sprite_coord_enable;
1171 }
1172
1173 static void r300_resource_resolve(struct pipe_context* pipe,
1174 struct pipe_resource* dest,
1175 unsigned dst_layer,
1176 struct pipe_resource* src,
1177 unsigned src_layer)
1178 {
1179 struct r300_context* r300 = r300_context(pipe);
1180 struct pipe_surface* srcsurf, surf_tmpl;
1181 struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state;
1182 float color[] = {0, 0, 0, 0};
1183
1184 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
1185 surf_tmpl.format = src->format;
1186 surf_tmpl.usage = 0; /* not really a surface hence no bind flags */
1187 surf_tmpl.u.tex.level = 0; /* msaa resources cannot have mipmaps */
1188 surf_tmpl.u.tex.first_layer = src_layer;
1189 surf_tmpl.u.tex.last_layer = src_layer;
1190 srcsurf = pipe->create_surface(pipe, src, &surf_tmpl);
1191 surf_tmpl.format = dest->format;
1192 surf_tmpl.u.tex.first_layer = dst_layer;
1193 surf_tmpl.u.tex.last_layer = dst_layer;
1194
1195 DBG(r300, DBG_DRAW, "r300: Resolving resource...\n");
1196
1197 /* Enable AA resolve. */
1198 aa->dest = r300_surface(pipe->create_surface(pipe, dest, &surf_tmpl));
1199
1200 aa->aaresolve_ctl =
1201 R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_RESOLVE |
1202 R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE;
1203 r300->aa_state.size = 10;
1204 r300_mark_atom_dirty(r300, &r300->aa_state);
1205
1206 /* Resolve the surface. */
1207 r300->context.clear_render_target(pipe,
1208 srcsurf, color, 0, 0, src->width0, src->height0);
1209
1210 /* Disable AA resolve. */
1211 aa->aaresolve_ctl = 0;
1212 r300->aa_state.size = 4;
1213 r300_mark_atom_dirty(r300, &r300->aa_state);
1214
1215 pipe_surface_reference((struct pipe_surface**)&srcsurf, NULL);
1216 pipe_surface_reference((struct pipe_surface**)&aa->dest, NULL);
1217 }
1218
1219 void r300_init_render_functions(struct r300_context *r300)
1220 {
1221 /* Set draw functions based on presence of HW TCL. */
1222 if (r300->screen->caps.has_tcl) {
1223 r300->context.draw_vbo = r300_draw_vbo;
1224 } else {
1225 r300->context.draw_vbo = r300_swtcl_draw_vbo;
1226 }
1227
1228 r300->context.resource_resolve = r300_resource_resolve;
1229 r300->blitter->draw_rectangle = r300_blitter_draw_rectangle;
1230
1231 /* Plug in the two-sided stencil reference value fallback if needed. */
1232 if (!r300->screen->caps.is_r500)
1233 r300_plug_in_stencil_ref_fallback(r300);
1234 }