1 /**************************************************************************
3 * Copyright 2009 Maciej Cencora
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHOR(S) AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/state.h"
32 #include "main/api_validate.h"
33 #include "main/enums.h"
34 #include "main/simple_list.h"
37 #include "r300_context.h"
38 #include "r300_emit.h"
39 #include "r300_render.h"
40 #include "r300_state.h"
42 #include "r300_cmdbuf.h"
44 #include "radeon_buffer_objects.h"
45 #include "radeon_common_context.h"
48 #include "tnl/t_vp_build.h"
49 #include "vbo/vbo_context.h"
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
54 static int getTypeSize(GLenum type
)
58 return sizeof(GLdouble
);
60 return sizeof(GLfloat
);
64 return sizeof(GLuint
);
66 return sizeof(GLshort
);
67 case GL_UNSIGNED_SHORT
:
68 return sizeof(GLushort
);
70 return sizeof(GLbyte
);
71 case GL_UNSIGNED_BYTE
:
72 return sizeof(GLubyte
);
79 static void r300FixupIndexBuffer(GLcontext
*ctx
, const struct _mesa_index_buffer
*mesa_ind_buf
)
81 r300ContextPtr r300
= R300_CONTEXT(ctx
);
85 GLboolean mapped_named_bo
= GL_FALSE
;
87 if (mesa_ind_buf
->obj
->Name
&& !mesa_ind_buf
->obj
->Pointer
) {
88 ctx
->Driver
.MapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, mesa_ind_buf
->obj
);
89 mapped_named_bo
= GL_TRUE
;
90 assert(mesa_ind_buf
->obj
->Pointer
!= NULL
);
92 src_ptr
= ADD_POINTERS(mesa_ind_buf
->obj
->Pointer
, mesa_ind_buf
->ptr
);
94 if (mesa_ind_buf
->type
== GL_UNSIGNED_BYTE
) {
95 GLuint size
= sizeof(GLushort
) * ((mesa_ind_buf
->count
+ 1) & ~1);
96 GLubyte
*in
= (GLubyte
*)src_ptr
;
98 radeonAllocDmaRegion(&r300
->radeon
, &r300
->ind_buf
.bo
, &r300
->ind_buf
.bo_offset
, size
, 4);
100 assert(r300
->ind_buf
.bo
->ptr
!= NULL
);
101 out
= (GLuint
*)ADD_POINTERS(r300
->ind_buf
.bo
->ptr
, r300
->ind_buf
.bo_offset
);
103 for (i
= 0; i
+ 1 < mesa_ind_buf
->count
; i
+= 2) {
104 *out
++ = in
[i
] | in
[i
+ 1] << 16;
107 if (i
< mesa_ind_buf
->count
) {
112 } else { /* if (mesa_ind_buf->type == GL_UNSIGNED_SHORT) */
113 GLushort
*in
= (GLushort
*)src_ptr
;
114 GLuint size
= sizeof(GLushort
) * ((mesa_ind_buf
->count
+ 1) & ~1);
116 radeonAllocDmaRegion(&r300
->radeon
, &r300
->ind_buf
.bo
,
117 &r300
->ind_buf
.bo_offset
, size
, 4);
119 assert(r300
->ind_buf
.bo
->ptr
!= NULL
);
120 out
= (GLuint
*)ADD_POINTERS(r300
->ind_buf
.bo
->ptr
, r300
->ind_buf
.bo_offset
);
122 for (i
= 0; i
+ 1 < mesa_ind_buf
->count
; i
+= 2) {
123 *out
++ = in
[i
] | in
[i
+ 1] << 16;
126 if (i
< mesa_ind_buf
->count
) {
132 r300
->ind_buf
.is_32bit
= GL_FALSE
;
133 r300
->ind_buf
.count
= mesa_ind_buf
->count
;
135 if (mapped_named_bo
) {
136 ctx
->Driver
.UnmapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, mesa_ind_buf
->obj
);
141 static void r300SetupIndexBuffer(GLcontext
*ctx
, const struct _mesa_index_buffer
*mesa_ind_buf
)
143 r300ContextPtr r300
= R300_CONTEXT(ctx
);
146 r300
->ind_buf
.bo
= NULL
;
151 if (mesa_ind_buf
->type
== GL_UNSIGNED_INT
) {
153 if (mesa_ind_buf
->type
!= GL_UNSIGNED_BYTE
) {
155 const GLvoid
*src_ptr
;
157 GLboolean mapped_named_bo
= GL_FALSE
;
159 if (mesa_ind_buf
->obj
->Name
&& !mesa_ind_buf
->obj
->Pointer
) {
160 ctx
->Driver
.MapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, mesa_ind_buf
->obj
);
161 assert(mesa_ind_buf
->obj
->Pointer
!= NULL
);
162 mapped_named_bo
= GL_TRUE
;
165 src_ptr
= ADD_POINTERS(mesa_ind_buf
->obj
->Pointer
, mesa_ind_buf
->ptr
);
167 const GLuint size
= mesa_ind_buf
->count
* getTypeSize(mesa_ind_buf
->type
);
169 radeonAllocDmaRegion(&r300
->radeon
, &r300
->ind_buf
.bo
, &r300
->ind_buf
.bo_offset
, size
, 4);
171 assert(r300
->ind_buf
.bo
->ptr
!= NULL
);
172 dst_ptr
= ADD_POINTERS(r300
->ind_buf
.bo
->ptr
, r300
->ind_buf
.bo_offset
);
173 _mesa_memcpy(dst_ptr
, src_ptr
, size
);
175 r300
->ind_buf
.is_32bit
= (mesa_ind_buf
->type
== GL_UNSIGNED_INT
);
176 r300
->ind_buf
.count
= mesa_ind_buf
->count
;
178 if (mapped_named_bo
) {
179 ctx
->Driver
.UnmapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, mesa_ind_buf
->obj
);
182 r300FixupIndexBuffer(ctx
, mesa_ind_buf
);
186 #define CONVERT( TYPE, MACRO ) do { \
189 if (input->Normalized) { \
190 for (i = 0; i < count; i++) { \
191 const TYPE *in = (TYPE *)src_ptr; \
192 for (j = 0; j < sz; j++) { \
193 *dst_ptr++ = MACRO(*in); \
199 for (i = 0; i < count; i++) { \
200 const TYPE *in = (TYPE *)src_ptr; \
201 for (j = 0; j < sz; j++) { \
202 *dst_ptr++ = (GLfloat)(*in); \
211 * Convert attribute data type to float
212 * If the attribute uses named buffer object replace the bo with newly allocated bo
214 static void r300ConvertAttrib(GLcontext
*ctx
, int count
, const struct gl_client_array
*input
, struct vertex_attribute
*attr
)
216 r300ContextPtr r300
= R300_CONTEXT(ctx
);
217 const GLvoid
*src_ptr
;
218 GLboolean mapped_named_bo
= GL_FALSE
;
222 stride
= (input
->StrideB
== 0) ? getTypeSize(input
->Type
) * input
->Size
: input
->StrideB
;
224 /* Convert value for first element only */
225 if (input
->StrideB
== 0)
228 if (input
->BufferObj
->Name
) {
229 if (!input
->BufferObj
->Pointer
) {
230 ctx
->Driver
.MapBuffer(ctx
, GL_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, input
->BufferObj
);
231 mapped_named_bo
= GL_TRUE
;
234 src_ptr
= ADD_POINTERS(input
->BufferObj
->Pointer
, input
->Ptr
);
236 src_ptr
= input
->Ptr
;
239 radeonAllocDmaRegion(&r300
->radeon
, &attr
->bo
, &attr
->bo_offset
, sizeof(GLfloat
) * input
->Size
* count
, 32);
240 dst_ptr
= (GLfloat
*)ADD_POINTERS(attr
->bo
->ptr
, attr
->bo_offset
);
242 if (RADEON_DEBUG
& DEBUG_FALLBACKS
) {
243 fprintf(stderr
, "%s: Converting vertex attributes, attribute data format %x,", __FUNCTION__
, input
->Type
);
244 fprintf(stderr
, "stride %d, components %d\n", stride
, input
->Size
);
247 assert(src_ptr
!= NULL
);
249 switch (input
->Type
) {
251 CONVERT(GLdouble
, (GLfloat
));
253 case GL_UNSIGNED_INT
:
254 CONVERT(GLuint
, UINT_TO_FLOAT
);
257 CONVERT(GLint
, INT_TO_FLOAT
);
259 case GL_UNSIGNED_SHORT
:
260 CONVERT(GLushort
, USHORT_TO_FLOAT
);
263 CONVERT(GLshort
, SHORT_TO_FLOAT
);
265 case GL_UNSIGNED_BYTE
:
266 assert(input
->Format
!= GL_BGRA
);
267 CONVERT(GLubyte
, UBYTE_TO_FLOAT
);
270 CONVERT(GLbyte
, BYTE_TO_FLOAT
);
277 if (mapped_named_bo
) {
278 ctx
->Driver
.UnmapBuffer(ctx
, GL_ARRAY_BUFFER
, input
->BufferObj
);
282 static void r300AlignDataToDword(GLcontext
*ctx
, const struct gl_client_array
*input
, int count
, struct vertex_attribute
*attr
)
284 r300ContextPtr r300
= R300_CONTEXT(ctx
);
285 const int dst_stride
= (input
->StrideB
+ 3) & ~3;
286 const int size
= getTypeSize(input
->Type
) * input
->Size
* count
;
287 GLboolean mapped_named_bo
= GL_FALSE
;
289 radeonAllocDmaRegion(&r300
->radeon
, &attr
->bo
, &attr
->bo_offset
, size
, 32);
291 if (!input
->BufferObj
->Pointer
) {
292 ctx
->Driver
.MapBuffer(ctx
, GL_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, input
->BufferObj
);
293 mapped_named_bo
= GL_TRUE
;
297 GLvoid
*src_ptr
= ADD_POINTERS(input
->BufferObj
->Pointer
, input
->Ptr
);
298 GLvoid
*dst_ptr
= ADD_POINTERS(attr
->bo
->ptr
, attr
->bo_offset
);
301 for (i
= 0; i
< count
; ++i
) {
302 _mesa_memcpy(dst_ptr
, src_ptr
, input
->StrideB
);
303 src_ptr
+= input
->StrideB
;
304 dst_ptr
+= dst_stride
;
308 if (mapped_named_bo
) {
309 ctx
->Driver
.UnmapBuffer(ctx
, GL_ARRAY_BUFFER
, input
->BufferObj
);
312 attr
->stride
= dst_stride
;
315 static void r300TranslateAttrib(GLcontext
*ctx
, GLuint attr
, int count
, const struct gl_client_array
*input
)
317 r300ContextPtr r300
= R300_CONTEXT(ctx
);
318 struct r300_vertex_buffer
*vbuf
= &r300
->vbuf
;
319 struct vertex_attribute r300_attr
;
323 stride
= (input
->StrideB
== 0) ? getTypeSize(input
->Type
) * input
->Size
: input
->StrideB
;
325 if (input
->Type
== GL_DOUBLE
|| input
->Type
== GL_UNSIGNED_INT
|| input
->Type
== GL_INT
||
327 getTypeSize(input
->Type
) != 4 ||
333 if (input
->StrideB
== 0) {
334 r300_attr
.stride
= 0;
336 r300_attr
.stride
= sizeof(GLfloat
) * input
->Size
;
338 r300_attr
.dwords
= input
->Size
;
339 r300_attr
.is_named_bo
= GL_FALSE
;
342 r300_attr
.dwords
= (getTypeSize(type
) * input
->Size
+ 3)/ 4;
343 if (!input
->BufferObj
->Name
) {
345 if (input
->StrideB
== 0) {
346 r300_attr
.stride
= 0;
348 r300_attr
.stride
= (getTypeSize(type
) * input
->Size
+ 3) & ~3;
351 r300_attr
.is_named_bo
= GL_FALSE
;
355 r300_attr
.size
= input
->Size
;
356 r300_attr
.element
= attr
;
357 r300_attr
.dst_loc
= vbuf
->num_attribs
;
361 switch (input
->Size
) {
362 case 1: r300_attr
.data_type
= R300_DATA_TYPE_FLOAT_1
; break;
363 case 2: r300_attr
.data_type
= R300_DATA_TYPE_FLOAT_2
; break;
364 case 3: r300_attr
.data_type
= R300_DATA_TYPE_FLOAT_3
; break;
365 case 4: r300_attr
.data_type
= R300_DATA_TYPE_FLOAT_4
; break;
367 r300_attr
._signed
= 0;
368 r300_attr
.normalize
= 0;
371 r300_attr
._signed
= 1;
372 r300_attr
.normalize
= input
->Normalized
;
373 switch (input
->Size
) {
376 r300_attr
.data_type
= R300_DATA_TYPE_SHORT_2
;
380 r300_attr
.data_type
= R300_DATA_TYPE_SHORT_4
;
385 r300_attr
._signed
= 1;
386 r300_attr
.normalize
= input
->Normalized
;
387 r300_attr
.data_type
= R300_DATA_TYPE_BYTE
;
389 case GL_UNSIGNED_SHORT
:
390 r300_attr
._signed
= 0;
391 r300_attr
.normalize
= input
->Normalized
;
392 switch (input
->Size
) {
395 r300_attr
.data_type
= R300_DATA_TYPE_SHORT_2
;
399 r300_attr
.data_type
= R300_DATA_TYPE_SHORT_4
;
403 case GL_UNSIGNED_BYTE
:
404 r300_attr
._signed
= 0;
405 r300_attr
.normalize
= input
->Normalized
;
406 if (input
->Format
== GL_BGRA
)
407 r300_attr
.data_type
= R300_DATA_TYPE_D3DCOLOR
;
409 r300_attr
.data_type
= R300_DATA_TYPE_BYTE
;
415 case GL_UNSIGNED_INT
:
420 switch (input
->Size
) {
422 r300_attr
.swizzle
= SWIZZLE_XYZW
;
425 r300_attr
.swizzle
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
428 r300_attr
.swizzle
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
431 r300_attr
.swizzle
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
435 r300_attr
.write_mask
= MASK_XYZW
;
437 vbuf
->attribs
[vbuf
->num_attribs
] = r300_attr
;
441 static void r300SetVertexFormat(GLcontext
*ctx
, const struct gl_client_array
*arrays
[], int count
)
443 r300ContextPtr r300
= R300_CONTEXT(ctx
);
444 struct r300_vertex_buffer
*vbuf
= &r300
->vbuf
;
448 tmp
= r300
->selected_vp
->code
.InputsRead
;
450 vbuf
->num_attribs
= 0;
452 /* find first enabled bit */
458 r300TranslateAttrib(ctx
, i
, count
, arrays
[i
]);
465 r300SwitchFallback(ctx
, R300_FALLBACK_AOS_LIMIT
, vbuf
->num_attribs
> R300_MAX_AOS_ARRAYS
);
470 static void r300AllocDmaRegions(GLcontext
*ctx
, const struct gl_client_array
*input
[], int count
)
472 r300ContextPtr r300
= R300_CONTEXT(ctx
);
473 struct r300_vertex_buffer
*vbuf
= &r300
->vbuf
;
478 for (index
= 0; index
< vbuf
->num_attribs
; index
++) {
479 struct radeon_aos
*aos
= &r300
->radeon
.tcl
.aos
[index
];
480 i
= vbuf
->attribs
[index
].element
;
482 stride
= (input
[i
]->StrideB
== 0) ? getTypeSize(input
[i
]->Type
) * input
[i
]->Size
: input
[i
]->StrideB
;
484 if (input
[i
]->Type
== GL_DOUBLE
|| input
[i
]->Type
== GL_UNSIGNED_INT
|| input
[i
]->Type
== GL_INT
||
486 getTypeSize(input
[i
]->Type
) != 4 ||
490 r300ConvertAttrib(ctx
, count
, input
[i
], &vbuf
->attribs
[index
]);
492 if (input
[i
]->BufferObj
->Name
) {
493 if (stride
% 4 != 0) {
494 assert(((intptr_t) input
[i
]->Ptr
) % input
[i
]->StrideB
== 0);
495 r300AlignDataToDword(ctx
, input
[i
], count
, &vbuf
->attribs
[index
]);
496 vbuf
->attribs
[index
].is_named_bo
= GL_FALSE
;
498 vbuf
->attribs
[index
].stride
= input
[i
]->StrideB
;
499 vbuf
->attribs
[index
].bo_offset
= (intptr_t) input
[i
]->Ptr
;
500 vbuf
->attribs
[index
].bo
= get_radeon_buffer_object(input
[i
]->BufferObj
)->bo
;
501 vbuf
->attribs
[index
].is_named_bo
= GL_TRUE
;
506 int local_count
= count
;
509 if (input
[i
]->StrideB
== 0) {
510 size
= getTypeSize(input
[i
]->Type
) * input
[i
]->Size
;
513 size
= getTypeSize(input
[i
]->Type
) * input
[i
]->Size
* local_count
;
516 radeonAllocDmaRegion(&r300
->radeon
, &vbuf
->attribs
[index
].bo
, &vbuf
->attribs
[index
].bo_offset
, size
, 32);
517 assert(vbuf
->attribs
[index
].bo
->ptr
!= NULL
);
518 dst
= (uint32_t *)ADD_POINTERS(vbuf
->attribs
[index
].bo
->ptr
, vbuf
->attribs
[index
].bo_offset
);
519 switch (vbuf
->attribs
[index
].dwords
) {
520 case 1: radeonEmitVec4(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
); break;
521 case 2: radeonEmitVec8(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
); break;
522 case 3: radeonEmitVec12(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
); break;
523 case 4: radeonEmitVec16(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
); break;
524 default: assert(0); break;
530 aos
->count
= vbuf
->attribs
[index
].stride
== 0 ? 1 : count
;
531 aos
->stride
= vbuf
->attribs
[index
].stride
/ sizeof(float);
532 aos
->components
= vbuf
->attribs
[index
].dwords
;
533 aos
->bo
= vbuf
->attribs
[index
].bo
;
534 aos
->offset
= vbuf
->attribs
[index
].bo_offset
;
536 if (vbuf
->attribs
[index
].is_named_bo
) {
537 radeon_cs_space_add_persistent_bo(r300
->radeon
.cmdbuf
.cs
, r300
->vbuf
.attribs
[index
].bo
, RADEON_GEM_DOMAIN_GTT
, 0);
541 r300
->radeon
.tcl
.aos_count
= vbuf
->num_attribs
;
542 ret
= radeon_cs_space_check_with_bo(r300
->radeon
.cmdbuf
.cs
, first_elem(&r300
->radeon
.dma
.reserved
)->bo
, RADEON_GEM_DOMAIN_GTT
, 0);
543 r300SwitchFallback(ctx
, R300_FALLBACK_INVALID_BUFFERS
, ret
);
547 static void r300FreeData(GLcontext
*ctx
)
549 /* Need to zero tcl.aos[n].bo and tcl.elt_dma_bo
550 * to prevent double unref in radeonReleaseArrays
551 * called during context destroy
553 r300ContextPtr r300
= R300_CONTEXT(ctx
);
557 for (i
= 0; i
< r300
->vbuf
.num_attribs
; i
++) {
558 if (!r300
->vbuf
.attribs
[i
].is_named_bo
) {
559 radeon_bo_unref(r300
->vbuf
.attribs
[i
].bo
);
561 r300
->radeon
.tcl
.aos
[i
].bo
= NULL
;
566 if (r300
->ind_buf
.bo
!= NULL
) {
567 radeon_bo_unref(r300
->ind_buf
.bo
);
572 static GLuint
r300PredictTryDrawPrimsSize(GLcontext
*ctx
, GLuint nr_prims
)
574 struct r300_context
*r300
= R300_CONTEXT(ctx
);
575 struct r300_vertex_buffer
*vbuf
= &r300
->vbuf
;
580 dwords
= 2*CACHE_FLUSH_BUFSZ
;
581 dwords
+= PRE_EMIT_STATE_BUFSZ
;
582 dwords
+= (AOS_BUFSZ(vbuf
->num_attribs
)
584 + FIREAOS_BUFSZ
)*nr_prims
;
586 state_size
= radeonCountStateEmitSize(&r300
->radeon
);
587 flushed
= rcommonEnsureCmdBufSpace(&r300
->radeon
,
591 dwords
+= radeonCountStateEmitSize(&r300
->radeon
);
593 dwords
+= state_size
;
595 if (RADEON_DEBUG
& DEBUG_PRIMS
)
596 fprintf(stderr
, "%s: total prediction size is %d.\n", __FUNCTION__
, dwords
);
600 static GLboolean
r300TryDrawPrims(GLcontext
*ctx
,
601 const struct gl_client_array
*arrays
[],
602 const struct _mesa_prim
*prim
,
604 const struct _mesa_index_buffer
*ib
,
608 struct r300_context
*r300
= R300_CONTEXT(ctx
);
611 if (RADEON_DEBUG
& DEBUG_PRIMS
)
612 fprintf(stderr
, "%s: %u (%d-%d) cs begin at %d\n",
613 __FUNCTION__
, nr_prims
, min_index
, max_index
, r300
->radeon
.cmdbuf
.cs
->cdw
);
616 _mesa_update_state( ctx
);
618 if (r300
->options
.hw_tcl_enabled
)
619 _tnl_UpdateFixedFunctionProgram(ctx
);
621 r300UpdateShaders(r300
);
623 r300SwitchFallback(ctx
, R300_FALLBACK_INVALID_BUFFERS
, !r300ValidateBuffers(ctx
));
625 r300SetVertexFormat(ctx
, arrays
, max_index
+ 1);
630 r300SetupVAP(ctx
, r300
->selected_vp
->code
.InputsRead
, r300
->selected_vp
->code
.OutputsWritten
);
632 r300UpdateShaderStates(r300
);
634 /* ensure we have the cmd buf space in advance to cover
635 * the state + DMA AOS pointers */
636 GLuint emit_end
= r300PredictTryDrawPrimsSize(ctx
, nr_prims
)
637 + r300
->radeon
.cmdbuf
.cs
->cdw
;
639 r300SetupIndexBuffer(ctx
, ib
);
641 r300AllocDmaRegions(ctx
, arrays
, max_index
+ 1);
646 r300EmitCacheFlush(r300
);
647 radeonEmitState(&r300
->radeon
);
649 for (i
= 0; i
< nr_prims
; ++i
) {
650 r300RunRenderPrimitive(ctx
, prim
[i
].start
, prim
[i
].start
+ prim
[i
].count
, prim
[i
].mode
);
653 r300EmitCacheFlush(r300
);
657 if (RADEON_DEBUG
& DEBUG_PRIMS
)
658 fprintf(stderr
, "%s: %u (%d-%d) cs ending at %d\n",
659 __FUNCTION__
, nr_prims
, min_index
, max_index
, r300
->radeon
.cmdbuf
.cs
->cdw
);
661 if (emit_end
< r300
->radeon
.cmdbuf
.cs
->cdw
)
662 WARN_ONCE("Rendering was %d commands larger than predicted size."
663 " We might overflow command buffer.\n", r300
->radeon
.cmdbuf
.cs
->cdw
- emit_end
);
668 static void r300DrawPrims(GLcontext
*ctx
,
669 const struct gl_client_array
*arrays
[],
670 const struct _mesa_prim
*prim
,
672 const struct _mesa_index_buffer
*ib
,
673 GLboolean index_bounds_valid
,
679 /* This check should get folded into just the places that
680 * min/max index are really needed.
682 if (!index_bounds_valid
) {
683 vbo_get_minmax_index(ctx
, prim
, ib
, &min_index
, &max_index
);
687 vbo_rebase_prims( ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
, r300DrawPrims
);
691 /* Make an attempt at drawing */
692 retval
= r300TryDrawPrims(ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
);
694 /* If failed run tnl pipeline - it should take care of fallbacks */
696 _tnl_draw_prims(ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
);
699 void r300InitDraw(GLcontext
*ctx
)
701 struct vbo_context
*vbo
= vbo_context(ctx
);
703 vbo
->draw_prims
= r300DrawPrims
;