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