2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
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:
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
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. */
24 /* r300_render: Vertex and index buffer primitive emission. Contains both
25 * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */
27 #include "draw/draw_context.h"
28 #include "draw/draw_vbuf.h"
30 #include "util/u_inlines.h"
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"
38 #include "r300_context.h"
39 #include "r300_screen_buffer.h"
40 #include "r300_emit.h"
45 #define IMMD_DWORDS 32
47 static uint32_t r300_translate_primitive(unsigned prim
)
50 case PIPE_PRIM_POINTS
:
51 return R300_VAP_VF_CNTL__PRIM_POINTS
;
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
;
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
;
75 static uint32_t r300_provoking_vertex_fixes(struct r300_context
*r300
,
78 struct r300_rs_state
* rs
= (struct r300_rs_state
*)r300
->rs_state
.state
;
79 uint32_t color_control
= rs
->color_control
;
81 /* By default (see r300_state.c:r300_create_rs_state) color_control is
82 * initialized to provoking the first vertex.
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)
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.
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.
99 if (rs
->rs
.flatshade_first
) {
101 case PIPE_PRIM_TRIANGLE_FAN
:
102 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND
;
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
;
110 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST
;
114 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST
;
117 return color_control
;
120 void r500_emit_index_bias(struct r300_context
*r300
, int index_bias
)
125 OUT_CS_REG(R500_VAP_INDEX_OFFSET
,
126 (index_bias
& 0xFFFFFF) | (index_bias
< 0 ? 1<<24 : 0));
130 static void r300_emit_draw_init(struct r300_context
*r300
, unsigned mode
,
131 unsigned min_index
, unsigned max_index
)
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);
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
)
153 struct pipe_vertex_buffer
*vb
, *vbufs
= r300
->vbuf_mgr
->vertex_buffer
;
154 struct pipe_vertex_element
*velem
= r300
->velems
->velem
;
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
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
);
169 /* Now set the minimum allowed value. */
170 *buffer_offset
= MAX2(-max_neg_bias
, index_bias
);
172 /* A positive index bias is OK. */
173 *buffer_offset
= index_bias
;
176 *index_offset
= index_bias
- *buffer_offset
;
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? */
188 * Check if the requested number of dwords is available in the CS and
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
195 static boolean
r300_reserve_cs_dwords(struct r300_context
*r300
,
196 enum r300_prepare_flags flags
,
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
;
204 /* Add dirty state, index offset, and AOS. */
206 cs_dwords
+= r300_get_num_dirty_dwords(r300
);
208 if (r300
->screen
->caps
.index_bias_supported
)
209 cs_dwords
+= 2; /* emit_index_offset */
211 if (emit_vertex_arrays
)
212 cs_dwords
+= 55; /* emit_vertex_arrays */
214 if (emit_vertex_arrays_swtcl
)
215 cs_dwords
+= 7; /* emit_vertex_arrays_swtcl */
218 cs_dwords
+= r300_get_num_cs_end_dwords(r300
);
220 /* Reserve requested CS space. */
221 if (cs_dwords
> (R300_MAX_CMDBUF_DWORDS
- r300
->cs
->cdw
)) {
222 r300
->context
.flush(&r300
->context
, 0, NULL
);
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
238 static boolean
r300_emit_states(struct r300_context
*r300
,
239 enum r300_prepare_flags flags
,
240 struct pipe_resource
*index_buffer
,
243 boolean user_buffers
)
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
;
251 /* Validate buffers and emit dirty state if needed. */
253 if (r300
->validate_buffers
) {
254 if (!r300_emit_buffer_validate(r300
, validate_vbos
,
256 fprintf(stderr
, "r300: CS space validation failed. "
257 "(not enough memory?) Skipping rendering.\n");
261 /* Consider the validation done only if everything was validated. */
263 r300
->validate_buffers
= FALSE
;
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
;
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
);
278 r500_emit_index_bias(r300
, 0);
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
);
287 r300
->vertex_arrays_dirty
= FALSE
;
288 r300
->vertex_arrays_indexed
= indexed
;
289 r300
->vertex_arrays_offset
= buffer_offset
;
292 if (emit_vertex_arrays_swtcl
)
293 r300_emit_vertex_arrays_swtcl(r300
, indexed
);
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
310 static boolean
r300_prepare_for_rendering(struct r300_context
*r300
,
311 enum r300_prepare_flags flags
,
312 struct pipe_resource
*index_buffer
,
316 boolean user_buffers
)
318 if (r300_reserve_cs_dwords(r300
, flags
, cs_dwords
))
319 flags
|= PREP_FIRST_DRAW
;
321 return r300_emit_states(r300
, flags
, index_buffer
, buffer_offset
,
322 index_bias
, user_buffers
);
325 static boolean
immd_is_good_idea(struct r300_context
*r300
,
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
;
334 if (DBG_ON(r300
, DBG_NO_IMMD
)) {
342 if (count
* r300
->velems
->vertex_size_dwords
> IMMD_DWORDS
) {
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
;
353 buf
= r300
->vbuf_mgr
->real_vertex_buffer
[vbi
];
355 if ((r300_resource(buf
)->domain
!= R300_DOMAIN_GTT
)) {
365 /*****************************************************************************
366 * The HWTCL draw functions. *
367 ****************************************************************************/
369 static void r300_draw_arrays_immediate(struct r300_context
*r300
,
370 unsigned mode
, unsigned start
,
373 struct pipe_vertex_element
* velem
;
374 struct pipe_vertex_buffer
* vbuf
;
375 unsigned vertex_element_count
= r300
->velems
->count
;
378 /* Size of the vertex, in dwords. */
379 unsigned vertex_size
= r300
->velems
->vertex_size_dwords
;
381 /* The number of dwords for this draw operation. */
382 unsigned dwords
= 4 + count
* vertex_size
;
384 /* Size of the vertex element, in dwords. */
385 unsigned size
[PIPE_MAX_ATTRIBS
];
387 /* Stride to the same attrib in the next vertex in the vertex buffer,
389 unsigned stride
[PIPE_MAX_ATTRIBS
];
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};
398 if (!r300_prepare_for_rendering(r300
, PREP_FIRST_DRAW
, NULL
, dwords
, 0, 0,
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;
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
],
415 PIPE_TRANSFER_UNSYNCHRONIZED
,
417 map
[vbi
] += (vbuf
->buffer_offset
/ 4) + stride
[i
] * start
;
419 mapelem
[i
] = map
[vbi
] + (velem
->src_offset
/ 4);
422 r300_emit_draw_init(r300
, mode
, 0, count
-1);
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
));
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
]);
439 for (i
= 0; i
< vertex_element_count
; i
++) {
440 vbi
= r300
->velems
->velem
[i
].vertex_buffer_index
;
443 pipe_buffer_unmap(&r300
->context
, transfer
[vbi
]);
444 transfer
[vbi
] = NULL
;
449 static void r300_emit_draw_arrays(struct r300_context
*r300
,
453 boolean alt_num_verts
= count
> 65535;
456 if (count
>= (1 << 24)) {
457 fprintf(stderr
, "r300: Got a huge number of vertices: %i, "
458 "refusing to render.\n", count
);
462 r300_emit_draw_init(r300
, mode
, 0, count
-1);
464 BEGIN_CS(2 + (alt_num_verts
? 2 : 0));
466 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES
, count
);
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));
475 static void r300_emit_draw_elements(struct r300_context
*r300
,
476 struct pipe_resource
* indexBuffer
,
483 uint16_t *imm_indices3
)
485 uint32_t count_dwords
, offset_dwords
;
486 boolean alt_num_verts
= count
> 65535;
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
);
495 DBG(r300
, DBG_DRAW
, "r300: Indexbuf of %u indices, min %u max %u\n",
496 count
, minIndex
, maxIndex
);
498 r300_emit_draw_init(r300
, mode
, minIndex
, maxIndex
);
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
) {
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]);
519 offset_dwords
= indexSize
* start
/ sizeof(uint32_t);
521 BEGIN_CS(8 + (alt_num_verts
? 2 : 0));
523 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES
, count
);
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));
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));
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
));
548 static void r300_draw_elements_immediate(struct r300_context
*r300
,
549 int indexBias
, unsigned minIndex
,
550 unsigned maxIndex
, unsigned mode
,
551 unsigned start
, unsigned count
,
552 boolean user_buffers
)
557 unsigned index_size
= r300
->index_buffer
.index_size
;
558 unsigned i
, count_dwords
= index_size
== 4 ? count
: (count
+ 1) / 2;
561 /* 19 dwords for r300_draw_elements_immediate. Give up if the function fails. */
562 if (!r300_prepare_for_rendering(r300
,
563 PREP_FIRST_DRAW
| PREP_VALIDATE_VBOS
| PREP_EMIT_AOS
|
564 PREP_INDEXED
, NULL
, 2+count_dwords
, 0, indexBias
,
568 r300_emit_draw_init(r300
, mode
, minIndex
, maxIndex
);
570 BEGIN_CS(2 + count_dwords
);
571 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2
, count_dwords
);
573 switch (index_size
) {
575 ptr1
= r300_resource(r300
->index_buffer
.buffer
)->b
.user_ptr
;
578 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
579 r300_translate_primitive(mode
));
581 if (indexBias
&& !r300
->screen
->caps
.index_bias_supported
) {
582 for (i
= 0; i
< count
-1; i
+= 2)
583 OUT_CS(((ptr1
[i
+1] + indexBias
) << 16) |
584 (ptr1
[i
] + indexBias
));
587 OUT_CS(ptr1
[i
] + indexBias
);
589 for (i
= 0; i
< count
-1; i
+= 2)
590 OUT_CS(((ptr1
[i
+1]) << 16) |
599 ptr2
= (uint16_t*)r300_resource(r300
->index_buffer
.buffer
)->b
.user_ptr
;
602 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
603 r300_translate_primitive(mode
));
605 if (indexBias
&& !r300
->screen
->caps
.index_bias_supported
) {
606 for (i
= 0; i
< count
-1; i
+= 2)
607 OUT_CS(((ptr2
[i
+1] + indexBias
) << 16) |
608 (ptr2
[i
] + indexBias
));
611 OUT_CS(ptr2
[i
] + indexBias
);
613 OUT_CS_TABLE(ptr2
, count_dwords
);
618 ptr4
= (uint32_t*)r300_resource(r300
->index_buffer
.buffer
)->b
.user_ptr
;
621 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
622 R300_VAP_VF_CNTL__INDEX_SIZE_32bit
|
623 r300_translate_primitive(mode
));
625 if (indexBias
&& !r300
->screen
->caps
.index_bias_supported
) {
626 for (i
= 0; i
< count
; i
++)
627 OUT_CS(ptr4
[i
] + indexBias
);
629 OUT_CS_TABLE(ptr4
, count_dwords
);
636 static void r300_draw_elements(struct r300_context
*r300
, int indexBias
,
637 unsigned minIndex
, unsigned maxIndex
,
638 unsigned mode
, unsigned start
, unsigned count
,
639 boolean user_buffers
)
641 struct pipe_resource
*indexBuffer
= r300
->index_buffer
.buffer
;
642 unsigned indexSize
= r300
->index_buffer
.index_size
;
643 struct pipe_resource
* orgIndexBuffer
= indexBuffer
;
644 boolean alt_num_verts
= r300
->screen
->caps
.is_r500
&&
646 r300
->rws
->get_value(r300
->rws
, R300_VID_DRM_2_3_0
);
647 unsigned short_count
;
648 int buffer_offset
= 0, index_offset
= 0; /* for index bias emulation */
649 uint16_t indices3
[3];
651 if (indexBias
&& !r300
->screen
->caps
.index_bias_supported
) {
652 r300_split_index_bias(r300
, indexBias
, &buffer_offset
, &index_offset
);
655 r300_translate_index_buffer(r300
, &indexBuffer
, &indexSize
, index_offset
,
658 /* Fallback for misaligned ushort indices. */
659 if (indexSize
== 2 && (start
& 1) &&
660 !r300_resource(indexBuffer
)->b
.user_ptr
) {
661 struct pipe_transfer
*transfer
;
663 uint16_t *ptr
= pipe_buffer_map(&r300
->context
, indexBuffer
,
665 PIPE_TRANSFER_UNSYNCHRONIZED
,
668 if (mode
== PIPE_PRIM_TRIANGLES
) {
669 memcpy(indices3
, ptr
+ start
, 6);
671 /* Copy the mapped index buffer directly to the upload buffer.
672 * The start index will be aligned simply from the fact that
673 * every sub-buffer in the upload buffer is aligned. */
674 r300_upload_index_buffer(r300
, &indexBuffer
, indexSize
, &start
,
675 count
, (uint8_t*)ptr
);
677 pipe_buffer_unmap(&r300
->context
, transfer
);
679 if (r300_resource(indexBuffer
)->b
.user_ptr
)
680 r300_upload_index_buffer(r300
, &indexBuffer
, indexSize
,
682 r300_resource(indexBuffer
)->b
.user_ptr
);
685 /* 19 dwords for emit_draw_elements. Give up if the function fails. */
686 if (!r300_prepare_for_rendering(r300
,
687 PREP_FIRST_DRAW
| PREP_VALIDATE_VBOS
| PREP_EMIT_AOS
|
688 PREP_INDEXED
, indexBuffer
, 19, buffer_offset
, indexBias
,
692 if (alt_num_verts
|| count
<= 65535) {
693 r300_emit_draw_elements(r300
, indexBuffer
, indexSize
,
694 minIndex
, maxIndex
, mode
, start
, count
, indices3
);
697 if (indexSize
== 2 && (start
& 1))
698 short_count
= MIN2(count
, 65535);
700 short_count
= MIN2(count
, 65534);
702 r300_emit_draw_elements(r300
, indexBuffer
, indexSize
,
704 mode
, start
, short_count
, indices3
);
706 start
+= short_count
;
707 count
-= short_count
;
709 /* 15 dwords for emit_draw_elements */
711 if (!r300_prepare_for_rendering(r300
,
712 PREP_VALIDATE_VBOS
| PREP_EMIT_AOS
| PREP_INDEXED
,
713 indexBuffer
, 19, buffer_offset
, indexBias
, user_buffers
))
720 if (indexBuffer
!= orgIndexBuffer
) {
721 pipe_resource_reference( &indexBuffer
, NULL
);
725 static void r300_draw_arrays(struct r300_context
*r300
, unsigned mode
,
726 unsigned start
, unsigned count
,
727 boolean user_buffers
)
729 boolean alt_num_verts
= r300
->screen
->caps
.is_r500
&&
731 r300
->rws
->get_value(r300
->rws
, R300_VID_DRM_2_3_0
);
732 unsigned short_count
;
734 /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
735 if (!r300_prepare_for_rendering(r300
,
736 PREP_FIRST_DRAW
| PREP_VALIDATE_VBOS
| PREP_EMIT_AOS
,
737 NULL
, 9, start
, 0, user_buffers
))
740 if (alt_num_verts
|| count
<= 65535) {
741 r300_emit_draw_arrays(r300
, mode
, count
);
744 short_count
= MIN2(count
, 65535);
745 r300_emit_draw_arrays(r300
, mode
, short_count
);
747 start
+= short_count
;
748 count
-= short_count
;
750 /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
752 if (!r300_prepare_for_rendering(r300
,
753 PREP_VALIDATE_VBOS
| PREP_EMIT_AOS
, NULL
, 9,
754 start
, 0, user_buffers
))
761 static void r300_draw_vbo(struct pipe_context
* pipe
,
762 const struct pipe_draw_info
*info
)
764 struct r300_context
* r300
= r300_context(pipe
);
765 unsigned count
= info
->count
;
766 boolean buffers_updated
, uploader_flushed
;
767 boolean indexed
= info
->indexed
&& r300
->index_buffer
.buffer
;
768 unsigned start_indexed
= info
->start
+ r300
->index_buffer
.offset
;
769 int max_index
= MIN2(r300
->vbuf_mgr
->max_index
, info
->max_index
);
771 if (r300
->skip_rendering
||
772 !u_trim_pipe_prim(info
->mode
, &count
)) {
776 /* Start the vbuf manager and update buffers if needed. */
777 u_vbuf_mgr_draw_begin(r300
->vbuf_mgr
, info
,
778 &buffers_updated
, &uploader_flushed
);
779 if (buffers_updated
) {
780 r300
->vertex_arrays_dirty
= TRUE
;
782 if (uploader_flushed
|| !r300
->upload_vb_validated
) {
783 r300
->upload_vb_validated
= FALSE
;
784 r300
->validate_buffers
= TRUE
;
787 r300
->upload_vb_validated
= FALSE
;
791 r300_update_derived_state(r300
);
795 r300_resource(r300
->index_buffer
.buffer
)->b
.user_ptr
) {
796 r300_draw_elements_immediate(r300
, info
->index_bias
,
797 info
->min_index
, max_index
,
798 info
->mode
, start_indexed
, count
,
801 r300_draw_elements(r300
, info
->index_bias
, info
->min_index
,
802 max_index
, info
->mode
, start_indexed
, count
,
806 if (immd_is_good_idea(r300
, count
)) {
807 r300_draw_arrays_immediate(r300
, info
->mode
, info
->start
, count
);
809 r300_draw_arrays(r300
, info
->mode
, info
->start
, count
,
814 u_vbuf_mgr_draw_end(r300
->vbuf_mgr
);
817 /****************************************************************************
818 * The rest of this file is for SW TCL rendering only. Please be polite and *
819 * keep these functions separated so that they are easier to locate. ~C. *
820 ***************************************************************************/
822 /* SW TCL elements, using Draw. */
823 static void r300_swtcl_draw_vbo(struct pipe_context
* pipe
,
824 const struct pipe_draw_info
*info
)
826 struct r300_context
* r300
= r300_context(pipe
);
827 struct pipe_transfer
*vb_transfer
[PIPE_MAX_ATTRIBS
];
828 struct pipe_transfer
*ib_transfer
= NULL
;
829 unsigned count
= info
->count
;
831 void *indices
= NULL
;
832 boolean indexed
= info
->indexed
&& r300
->index_buffer
.buffer
;
834 if (r300
->skip_rendering
) {
838 if (!u_trim_pipe_prim(info
->mode
, &count
)) {
842 r300_update_derived_state(r300
);
844 r300_reserve_cs_dwords(r300
,
845 PREP_FIRST_DRAW
| PREP_EMIT_AOS_SWTCL
|
846 (indexed
? PREP_INDEXED
: 0),
849 for (i
= 0; i
< r300
->vbuf_mgr
->nr_vertex_buffers
; i
++) {
850 if (r300
->vbuf_mgr
->vertex_buffer
[i
].buffer
) {
851 void *buf
= pipe_buffer_map(pipe
,
852 r300
->vbuf_mgr
->vertex_buffer
[i
].buffer
,
854 PIPE_TRANSFER_UNSYNCHRONIZED
,
856 draw_set_mapped_vertex_buffer(r300
->draw
, i
, buf
);
861 indices
= pipe_buffer_map(pipe
, r300
->index_buffer
.buffer
,
863 PIPE_TRANSFER_UNSYNCHRONIZED
, &ib_transfer
);
866 draw_set_mapped_index_buffer(r300
->draw
, indices
);
868 r300
->draw_vbo_locked
= TRUE
;
869 r300
->draw_first_emitted
= FALSE
;
870 draw_vbo(r300
->draw
, info
);
871 draw_flush(r300
->draw
);
872 r300
->draw_vbo_locked
= FALSE
;
874 for (i
= 0; i
< r300
->vbuf_mgr
->nr_vertex_buffers
; i
++) {
875 if (r300
->vbuf_mgr
->vertex_buffer
[i
].buffer
) {
876 pipe_buffer_unmap(pipe
, vb_transfer
[i
]);
877 draw_set_mapped_vertex_buffer(r300
->draw
, i
, NULL
);
882 pipe_buffer_unmap(pipe
, ib_transfer
);
883 draw_set_mapped_index_buffer(r300
->draw
, NULL
);
887 /* Object for rendering using Draw. */
890 struct vbuf_render base
;
893 struct r300_context
* r300
;
895 /* Vertex information */
904 struct pipe_transfer
*vbo_transfer
;
907 static INLINE
struct r300_render
*
908 r300_render(struct vbuf_render
* render
)
910 return (struct r300_render
*)render
;
913 static const struct vertex_info
*
914 r300_render_get_vertex_info(struct vbuf_render
* render
)
916 struct r300_render
* r300render
= r300_render(render
);
917 struct r300_context
* r300
= r300render
->r300
;
919 return &r300
->vertex_info
;
922 static boolean
r300_render_allocate_vertices(struct vbuf_render
* render
,
926 struct r300_render
* r300render
= r300_render(render
);
927 struct r300_context
* r300
= r300render
->r300
;
928 struct pipe_screen
* screen
= r300
->context
.screen
;
929 size_t size
= (size_t)vertex_size
* (size_t)count
;
931 DBG(r300
, DBG_DRAW
, "r300: render_allocate_vertices (size: %d)\n", size
);
933 if (size
+ r300
->draw_vbo_offset
> r300
->draw_vbo_size
)
935 pipe_resource_reference(&r300
->vbo
, NULL
);
936 r300
->vbo
= pipe_buffer_create(screen
,
937 PIPE_BIND_VERTEX_BUFFER
,
938 R300_MAX_DRAW_VBO_SIZE
);
939 r300
->draw_vbo_offset
= 0;
940 r300
->draw_vbo_size
= R300_MAX_DRAW_VBO_SIZE
;
941 r300
->validate_buffers
= TRUE
;
944 r300render
->vertex_size
= vertex_size
;
946 return (r300
->vbo
) ? TRUE
: FALSE
;
949 static void* r300_render_map_vertices(struct vbuf_render
* render
)
951 struct r300_render
* r300render
= r300_render(render
);
952 struct r300_context
* r300
= r300render
->r300
;
954 assert(!r300render
->vbo_transfer
);
956 DBG(r300
, DBG_DRAW
, "r300: render_map_vertices\n");
958 r300render
->vbo_ptr
= pipe_buffer_map(&r300render
->r300
->context
,
960 PIPE_TRANSFER_WRITE
|
961 PIPE_TRANSFER_UNSYNCHRONIZED
,
962 &r300render
->vbo_transfer
);
964 assert(r300render
->vbo_ptr
);
966 return ((uint8_t*)r300render
->vbo_ptr
+ r300
->draw_vbo_offset
);
969 static void r300_render_unmap_vertices(struct vbuf_render
* render
,
973 struct r300_render
* r300render
= r300_render(render
);
974 struct pipe_context
* context
= &r300render
->r300
->context
;
975 struct r300_context
* r300
= r300render
->r300
;
977 assert(r300render
->vbo_transfer
);
979 DBG(r300
, DBG_DRAW
, "r300: render_unmap_vertices\n");
981 r300render
->vbo_max_used
= MAX2(r300render
->vbo_max_used
,
982 r300render
->vertex_size
* (max
+ 1));
983 pipe_buffer_unmap(context
, r300render
->vbo_transfer
);
985 r300render
->vbo_transfer
= NULL
;
988 static void r300_render_release_vertices(struct vbuf_render
* render
)
990 struct r300_render
* r300render
= r300_render(render
);
991 struct r300_context
* r300
= r300render
->r300
;
993 DBG(r300
, DBG_DRAW
, "r300: render_release_vertices\n");
995 r300
->draw_vbo_offset
+= r300render
->vbo_max_used
;
996 r300render
->vbo_max_used
= 0;
999 static boolean
r300_render_set_primitive(struct vbuf_render
* render
,
1002 struct r300_render
* r300render
= r300_render(render
);
1004 r300render
->prim
= prim
;
1005 r300render
->hwprim
= r300_translate_primitive(prim
);
1010 static void r300_render_draw_arrays(struct vbuf_render
* render
,
1014 struct r300_render
* r300render
= r300_render(render
);
1015 struct r300_context
* r300
= r300render
->r300
;
1018 unsigned dwords
= 6;
1021 (void) i
; (void) ptr
;
1023 DBG(r300
, DBG_DRAW
, "r300: render_draw_arrays (count: %d)\n", count
);
1025 if (r300
->draw_first_emitted
) {
1026 if (!r300_prepare_for_rendering(r300
,
1027 PREP_FIRST_DRAW
| PREP_EMIT_AOS_SWTCL
,
1028 NULL
, dwords
, 0, 0, FALSE
))
1031 if (!r300_emit_states(r300
,
1032 PREP_FIRST_DRAW
| PREP_EMIT_AOS_SWTCL
,
1038 OUT_CS_REG(R300_GA_COLOR_CONTROL
,
1039 r300_provoking_vertex_fixes(r300
, r300render
->prim
));
1040 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX
, count
- 1);
1041 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
1042 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (count
<< 16) |
1043 r300render
->hwprim
);
1046 r300
->draw_first_emitted
= TRUE
;
1049 static void r300_render_draw_elements(struct vbuf_render
* render
,
1050 const ushort
* indices
,
1053 struct r300_render
* r300render
= r300_render(render
);
1054 struct r300_context
* r300
= r300render
->r300
;
1056 unsigned end_cs_dwords
;
1057 unsigned max_index
= (r300
->draw_vbo_size
- r300
->draw_vbo_offset
) /
1058 (r300render
->r300
->vertex_info
.size
* 4) - 1;
1059 unsigned short_count
;
1060 unsigned free_dwords
;
1063 DBG(r300
, DBG_DRAW
, "r300: render_draw_elements (count: %d)\n", count
);
1065 if (r300
->draw_first_emitted
) {
1066 if (!r300_prepare_for_rendering(r300
,
1067 PREP_FIRST_DRAW
| PREP_EMIT_AOS_SWTCL
| PREP_INDEXED
,
1068 NULL
, 256, 0, 0, FALSE
))
1071 if (!r300_emit_states(r300
,
1072 PREP_FIRST_DRAW
| PREP_EMIT_AOS_SWTCL
| PREP_INDEXED
,
1077 /* Below we manage the CS space manually because there may be more
1078 * indices than it can fit in CS. */
1080 end_cs_dwords
= r300_get_num_cs_end_dwords(r300
);
1083 free_dwords
= R300_MAX_CMDBUF_DWORDS
- r300
->cs
->cdw
;
1085 short_count
= MIN2(count
, (free_dwords
- end_cs_dwords
- 6) * 2);
1087 BEGIN_CS(6 + (short_count
+1)/2);
1088 OUT_CS_REG(R300_GA_COLOR_CONTROL
,
1089 r300_provoking_vertex_fixes(r300
, r300render
->prim
));
1090 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX
, max_index
);
1091 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2
, (short_count
+1)/2);
1092 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (short_count
<< 16) |
1093 r300render
->hwprim
);
1094 for (i
= 0; i
< short_count
-1; i
+= 2) {
1095 OUT_CS(indices
[i
+1] << 16 | indices
[i
]);
1097 if (short_count
% 2) {
1098 OUT_CS(indices
[short_count
-1]);
1102 /* OK now subtract the emitted indices and see if we need to emit
1103 * another draw packet. */
1104 indices
+= short_count
;
1105 count
-= short_count
;
1108 if (!r300_prepare_for_rendering(r300
,
1109 PREP_EMIT_AOS_SWTCL
| PREP_INDEXED
,
1110 NULL
, 256, 0, 0, FALSE
))
1113 end_cs_dwords
= r300_get_num_cs_end_dwords(r300
);
1117 r300
->draw_first_emitted
= TRUE
;
1120 static void r300_render_destroy(struct vbuf_render
* render
)
1125 static struct vbuf_render
* r300_render_create(struct r300_context
* r300
)
1127 struct r300_render
* r300render
= CALLOC_STRUCT(r300_render
);
1129 r300render
->r300
= r300
;
1131 r300render
->base
.max_vertex_buffer_bytes
= 1024 * 1024;
1132 r300render
->base
.max_indices
= 16 * 1024;
1134 r300render
->base
.get_vertex_info
= r300_render_get_vertex_info
;
1135 r300render
->base
.allocate_vertices
= r300_render_allocate_vertices
;
1136 r300render
->base
.map_vertices
= r300_render_map_vertices
;
1137 r300render
->base
.unmap_vertices
= r300_render_unmap_vertices
;
1138 r300render
->base
.set_primitive
= r300_render_set_primitive
;
1139 r300render
->base
.draw_elements
= r300_render_draw_elements
;
1140 r300render
->base
.draw_arrays
= r300_render_draw_arrays
;
1141 r300render
->base
.release_vertices
= r300_render_release_vertices
;
1142 r300render
->base
.destroy
= r300_render_destroy
;
1144 return &r300render
->base
;
1147 struct draw_stage
* r300_draw_stage(struct r300_context
* r300
)
1149 struct vbuf_render
* render
;
1150 struct draw_stage
* stage
;
1152 render
= r300_render_create(r300
);
1158 stage
= draw_vbuf_stage(r300
->draw
, render
);
1161 render
->destroy(render
);
1165 draw_set_render(r300
->draw
, render
);
1170 void r300_draw_flush_vbuf(struct r300_context
*r300
)
1172 pipe_resource_reference(&r300
->vbo
, NULL
);
1173 r300
->draw_vbo_size
= 0;
1176 /****************************************************************************
1177 * End of SW TCL functions *
1178 ***************************************************************************/
1180 /* This functions is used to draw a rectangle for the blitter module.
1182 * If we rendered a quad, the pixels on the main diagonal
1183 * would be computed and stored twice, which makes the clear/copy codepaths
1184 * somewhat inefficient. Instead we use a rectangular point sprite. */
1185 static void r300_blitter_draw_rectangle(struct blitter_context
*blitter
,
1186 unsigned x1
, unsigned y1
,
1187 unsigned x2
, unsigned y2
,
1189 enum blitter_attrib_type type
,
1190 const float attrib
[4])
1192 struct r300_context
*r300
= r300_context(util_blitter_get_pipe(blitter
));
1193 unsigned last_sprite_coord_enable
= r300
->sprite_coord_enable
;
1194 unsigned width
= x2
- x1
;
1195 unsigned height
= y2
- y1
;
1196 unsigned vertex_size
=
1197 type
== UTIL_BLITTER_ATTRIB_COLOR
|| !r300
->draw
? 8 : 4;
1198 unsigned dwords
= 13 + vertex_size
+
1199 (type
== UTIL_BLITTER_ATTRIB_TEXCOORD
? 7 : 0);
1200 const float zeros
[4] = {0, 0, 0, 0};
1203 r300
->context
.set_vertex_buffers(&r300
->context
, 0, NULL
);
1205 if (type
== UTIL_BLITTER_ATTRIB_TEXCOORD
)
1206 r300
->sprite_coord_enable
= 1;
1208 r300_update_derived_state(r300
);
1210 /* Mark some states we don't care about as non-dirty. */
1211 r300
->clip_state
.dirty
= FALSE
;
1212 r300
->viewport_state
.dirty
= FALSE
;
1214 if (!r300_prepare_for_rendering(r300
, PREP_FIRST_DRAW
, NULL
, dwords
, 0, 0,
1218 DBG(r300
, DBG_DRAW
, "r300: draw_rectangle\n");
1222 OUT_CS_REG(R300_GA_POINT_SIZE
, (height
* 6) | ((width
* 6) << 16));
1224 if (type
== UTIL_BLITTER_ATTRIB_TEXCOORD
) {
1225 /* Set up the GA to generate texcoords. */
1226 OUT_CS_REG(R300_GB_ENABLE
, R300_GB_POINT_STUFF_ENABLE
|
1227 (R300_GB_TEX_STR
<< R300_GB_TEX0_SOURCE_SHIFT
));
1228 OUT_CS_REG_SEQ(R300_GA_POINT_S0
, 4);
1229 OUT_CS_32F(attrib
[0]);
1230 OUT_CS_32F(attrib
[3]);
1231 OUT_CS_32F(attrib
[2]);
1232 OUT_CS_32F(attrib
[1]);
1235 /* Set up VAP controls. */
1236 OUT_CS_REG(R300_VAP_CLIP_CNTL
, R300_CLIP_DISABLE
);
1237 OUT_CS_REG(R300_VAP_VTE_CNTL
, R300_VTX_XY_FMT
| R300_VTX_Z_FMT
);
1238 OUT_CS_REG(R300_VAP_VTX_SIZE
, vertex_size
);
1239 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX
, 2);
1244 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2
, vertex_size
);
1245 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED
| (1 << 16) |
1246 R300_VAP_VF_CNTL__PRIM_POINTS
);
1248 OUT_CS_32F(x1
+ width
* 0.5f
);
1249 OUT_CS_32F(y1
+ height
* 0.5f
);
1253 if (vertex_size
== 8) {
1256 OUT_CS_TABLE(attrib
, 4);
1261 /* Restore the state. */
1262 r300_mark_atom_dirty(r300
, &r300
->clip_state
);
1263 r300_mark_atom_dirty(r300
, &r300
->rs_state
);
1264 r300_mark_atom_dirty(r300
, &r300
->viewport_state
);
1266 r300
->sprite_coord_enable
= last_sprite_coord_enable
;
1269 static void r300_resource_resolve(struct pipe_context
* pipe
,
1270 struct pipe_resource
* dest
,
1272 struct pipe_resource
* src
,
1275 struct r300_context
* r300
= r300_context(pipe
);
1276 struct pipe_surface
* srcsurf
, surf_tmpl
;
1277 struct r300_aa_state
*aa
= (struct r300_aa_state
*)r300
->aa_state
.state
;
1278 float color
[] = {0, 0, 0, 0};
1280 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
1281 surf_tmpl
.format
= src
->format
;
1282 surf_tmpl
.usage
= 0; /* not really a surface hence no bind flags */
1283 surf_tmpl
.u
.tex
.level
= 0; /* msaa resources cannot have mipmaps */
1284 surf_tmpl
.u
.tex
.first_layer
= src_layer
;
1285 surf_tmpl
.u
.tex
.last_layer
= src_layer
;
1286 srcsurf
= pipe
->create_surface(pipe
, src
, &surf_tmpl
);
1287 surf_tmpl
.format
= dest
->format
;
1288 surf_tmpl
.u
.tex
.first_layer
= dst_layer
;
1289 surf_tmpl
.u
.tex
.last_layer
= dst_layer
;
1291 DBG(r300
, DBG_DRAW
, "r300: Resolving resource...\n");
1293 /* Enable AA resolve. */
1294 aa
->dest
= r300_surface(pipe
->create_surface(pipe
, dest
, &surf_tmpl
));
1297 R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_RESOLVE
|
1298 R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE
;
1299 r300
->aa_state
.size
= 10;
1300 r300_mark_atom_dirty(r300
, &r300
->aa_state
);
1302 /* Resolve the surface. */
1303 r300
->context
.clear_render_target(pipe
,
1304 srcsurf
, color
, 0, 0, src
->width0
, src
->height0
);
1306 /* Disable AA resolve. */
1307 aa
->aaresolve_ctl
= 0;
1308 r300
->aa_state
.size
= 4;
1309 r300_mark_atom_dirty(r300
, &r300
->aa_state
);
1311 pipe_surface_reference((struct pipe_surface
**)&srcsurf
, NULL
);
1312 pipe_surface_reference((struct pipe_surface
**)&aa
->dest
, NULL
);
1315 void r300_init_render_functions(struct r300_context
*r300
)
1317 /* Set draw functions based on presence of HW TCL. */
1318 if (r300
->screen
->caps
.has_tcl
) {
1319 r300
->context
.draw_vbo
= r300_draw_vbo
;
1321 r300
->context
.draw_vbo
= r300_swtcl_draw_vbo
;
1324 r300
->context
.resource_resolve
= r300_resource_resolve
;
1325 r300
->blitter
->draw_rectangle
= r300_blitter_draw_rectangle
;
1327 /* Plug in the two-sided stencil reference value fallback if needed. */
1328 if (!r300
->screen
->caps
.is_r500
)
1329 r300_plug_in_stencil_ref_fallback(r300
);