2 * Copyright (C) 2008-2010 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
27 #include "main/glheader.h"
28 #include "main/state.h"
29 #include "main/imports.h"
30 #include "main/enums.h"
31 #include "main/macros.h"
32 #include "main/context.h"
34 #include "main/simple_list.h"
35 #include "main/api_arrayelt.h"
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
41 #include "tnl/t_vp_build.h"
42 #include "tnl/t_context.h"
43 #include "tnl/t_vertex.h"
44 #include "vbo/vbo_context.h"
46 #include "r600_context.h"
47 #include "r600_cmdbuf.h"
49 #include "evergreen_fragprog.h"
50 #include "evergreen_vertprog.h"
52 #include "evergreen_state.h"
53 #include "evergreen_tex.h"
55 #include "radeon_buffer_objects.h"
56 #include "radeon_common_context.h"
58 static unsigned int evergreenPrimitiveType(int prim
) //same
60 switch (prim
& PRIM_MODE_MASK
)
63 return DI_PT_POINTLIST
;
66 return DI_PT_LINELIST
;
69 return DI_PT_LINESTRIP
;
72 return DI_PT_LINELOOP
;
77 case GL_TRIANGLE_STRIP
:
78 return DI_PT_TRISTRIP
;
84 return DI_PT_QUADLIST
;
87 return DI_PT_QUADSTRIP
;
99 static int evergreenNumVerts(int num_verts
, int prim
) //same
103 switch (prim
& PRIM_MODE_MASK
) {
108 verts_off
= num_verts
% 2;
112 verts_off
= num_verts
;
116 verts_off
= num_verts
;
119 verts_off
= num_verts
% 3;
121 case GL_TRIANGLE_STRIP
:
123 verts_off
= num_verts
;
125 case GL_TRIANGLE_FAN
:
127 verts_off
= num_verts
;
130 verts_off
= num_verts
% 4;
134 verts_off
= num_verts
;
136 verts_off
= num_verts
% 2;
140 verts_off
= num_verts
;
148 return num_verts
- verts_off
;
151 static void evergreenRunRenderPrimitive(struct gl_context
* ctx
, int start
, int end
, int prim
,
152 GLint basevertex
) //same
154 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
155 BATCH_LOCALS(&context
->radeon
);
156 int type
, total_emit
;
158 uint32_t vgt_draw_initiator
= 0;
159 uint32_t vgt_index_type
= 0;
160 uint32_t vgt_primitive_type
= 0;
161 uint32_t vgt_num_indices
= 0;
163 type
= evergreenPrimitiveType(prim
);
164 num_indices
= evergreenNumVerts(end
- start
, prim
);
166 radeon_print(RADEON_RENDER
, RADEON_TRACE
,
167 "%s type %x num_indices %d\n",
168 __func__
, type
, num_indices
);
170 if (type
< 0 || num_indices
<= 0)
173 SETfield(vgt_primitive_type
, type
,
174 VGT_PRIMITIVE_TYPE__PRIM_TYPE_shift
, VGT_PRIMITIVE_TYPE__PRIM_TYPE_mask
);
176 SETfield(vgt_index_type
, DI_INDEX_SIZE_32_BIT
, INDEX_TYPE_shift
, INDEX_TYPE_mask
);
178 if(GL_TRUE
!= context
->ind_buf
.is_32bit
)
180 SETfield(vgt_index_type
, DI_INDEX_SIZE_16_BIT
, INDEX_TYPE_shift
, INDEX_TYPE_mask
);
183 vgt_num_indices
= num_indices
;
184 SETfield(vgt_draw_initiator
, DI_SRC_SEL_DMA
, SOURCE_SELECT_shift
, SOURCE_SELECT_mask
);
185 SETfield(vgt_draw_initiator
, DI_MAJOR_MODE_0
, MAJOR_MODE_shift
, MAJOR_MODE_mask
);
187 total_emit
= 3 /* VGT_PRIMITIVE_TYPE */
188 + 2 /* VGT_INDEX_TYPE */
189 + 2 /* NUM_INSTANCES */
190 + 4 /* VTX_BASE_VTX_LOC + VTX_START_INST_LOC */
191 + 5 + 2; /* DRAW_INDEX */
193 BEGIN_BATCH_NO_AUTOSTATE(total_emit
);
195 R600_OUT_BATCH_REGSEQ(VGT_PRIMITIVE_TYPE
, 1);
196 R600_OUT_BATCH(vgt_primitive_type
);
198 R600_OUT_BATCH(CP_PACKET3(R600_IT_INDEX_TYPE
, 0));
199 R600_OUT_BATCH(vgt_index_type
);
201 R600_OUT_BATCH(CP_PACKET3(R600_IT_NUM_INSTANCES
, 0));
204 R600_OUT_BATCH(CP_PACKET3(R600_IT_SET_CTL_CONST
, 2));
205 R600_OUT_BATCH(mmSQ_VTX_BASE_VTX_LOC
- ASIC_CTL_CONST_BASE_INDEX
);
206 R600_OUT_BATCH(basevertex
); //VTX_BASE_VTX_LOC
207 R600_OUT_BATCH(0); //VTX_START_INST_LOC
209 R600_OUT_BATCH(CP_PACKET3(R600_IT_DRAW_INDEX
, 3));
210 R600_OUT_BATCH(context
->ind_buf
.bo_offset
);
212 R600_OUT_BATCH(vgt_num_indices
);
213 R600_OUT_BATCH(vgt_draw_initiator
);
214 R600_OUT_BATCH_RELOC(context
->ind_buf
.bo_offset
,
216 context
->ind_buf
.bo_offset
,
217 RADEON_GEM_DOMAIN_GTT
, 0, 0);
222 static void evergreenRunRenderPrimitiveImmediate(struct gl_context
* ctx
, int start
, int end
, int prim
) //same
224 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
225 BATCH_LOCALS(&context
->radeon
);
227 uint32_t num_indices
, total_emit
= 0;
228 uint32_t vgt_draw_initiator
= 0;
229 uint32_t vgt_index_type
= 0;
230 uint32_t vgt_primitive_type
= 0;
231 uint32_t vgt_num_indices
= 0;
233 type
= evergreenPrimitiveType(prim
);
234 num_indices
= evergreenNumVerts(end
- start
, prim
);
236 radeon_print(RADEON_RENDER
, RADEON_TRACE
,
237 "%s type %x num_indices %d\n",
238 __func__
, type
, num_indices
);
240 if (type
< 0 || num_indices
<= 0)
243 SETfield(vgt_primitive_type
, type
,
244 VGT_PRIMITIVE_TYPE__PRIM_TYPE_shift
, VGT_PRIMITIVE_TYPE__PRIM_TYPE_mask
);
246 if (num_indices
> 0xffff)
248 SETfield(vgt_index_type
, DI_INDEX_SIZE_32_BIT
, INDEX_TYPE_shift
, INDEX_TYPE_mask
);
252 SETfield(vgt_index_type
, DI_INDEX_SIZE_16_BIT
, INDEX_TYPE_shift
, INDEX_TYPE_mask
);
255 vgt_num_indices
= num_indices
;
256 SETfield(vgt_draw_initiator
, DI_MAJOR_MODE_0
, MAJOR_MODE_shift
, MAJOR_MODE_mask
);
260 SETfield(vgt_draw_initiator
, DI_SRC_SEL_AUTO_INDEX
, SOURCE_SELECT_shift
, SOURCE_SELECT_mask
);
264 if (num_indices
> 0xffff)
266 total_emit
+= num_indices
;
270 total_emit
+= (num_indices
+ 1) / 2;
272 SETfield(vgt_draw_initiator
, DI_SRC_SEL_IMMEDIATE
, SOURCE_SELECT_shift
, SOURCE_SELECT_mask
);
275 total_emit
+= 3 /* VGT_PRIMITIVE_TYPE */
276 + 2 /* VGT_INDEX_TYPE */
277 + 2 /* NUM_INSTANCES */
278 + 4 /* VTX_BASE_VTX_LOC + VTX_START_INST_LOC */
281 BEGIN_BATCH_NO_AUTOSTATE(total_emit
);
283 R600_OUT_BATCH_REGSEQ(VGT_PRIMITIVE_TYPE
, 1);
284 R600_OUT_BATCH(vgt_primitive_type
);
286 R600_OUT_BATCH(CP_PACKET3(R600_IT_INDEX_TYPE
, 0));
287 R600_OUT_BATCH(vgt_index_type
);
289 R600_OUT_BATCH(CP_PACKET3(R600_IT_NUM_INSTANCES
, 0));
292 R600_OUT_BATCH(CP_PACKET3(R600_IT_SET_CTL_CONST
, 2));
293 R600_OUT_BATCH(mmSQ_VTX_BASE_VTX_LOC
- ASIC_CTL_CONST_BASE_INDEX
);
294 R600_OUT_BATCH(0); //VTX_BASE_VTX_LOC
295 R600_OUT_BATCH(0); //VTX_START_INST_LOC
299 R600_OUT_BATCH(CP_PACKET3(R600_IT_DRAW_INDEX_AUTO
, 1));
300 R600_OUT_BATCH(vgt_num_indices
);
301 R600_OUT_BATCH(vgt_draw_initiator
);
305 if (num_indices
> 0xffff)
307 R600_OUT_BATCH(CP_PACKET3(R600_IT_DRAW_INDEX_IMMD
, (num_indices
+ 1)));
308 R600_OUT_BATCH(vgt_num_indices
);
309 R600_OUT_BATCH(vgt_draw_initiator
);
310 for (i
= start
; i
< (start
+ num_indices
); i
++)
317 R600_OUT_BATCH(CP_PACKET3(R600_IT_DRAW_INDEX_IMMD
, (((num_indices
+ 1) / 2) + 1)));
318 R600_OUT_BATCH(vgt_num_indices
);
319 R600_OUT_BATCH(vgt_draw_initiator
);
320 for (i
= start
; i
< (start
+ num_indices
); i
+= 2)
322 if ((i
+ 1) == (start
+ num_indices
))
328 R600_OUT_BATCH(((i
+ 1) << 16) | (i
));
338 #define CONVERT( TYPE, MACRO ) do { \
341 if (input->Normalized) { \
342 for (i = 0; i < count; i++) { \
343 const TYPE *in = (TYPE *)src_ptr; \
344 for (j = 0; j < sz; j++) { \
345 *dst_ptr++ = MACRO(*in); \
351 for (i = 0; i < count; i++) { \
352 const TYPE *in = (TYPE *)src_ptr; \
353 for (j = 0; j < sz; j++) { \
354 *dst_ptr++ = (GLfloat)(*in); \
363 * Convert attribute data type to float
364 * If the attribute uses named buffer object replace the bo with newly allocated bo
366 static void evergreenConvertAttrib(struct gl_context
*ctx
, int count
,
367 const struct gl_client_array
*input
,
368 struct StreamDesc
*attr
)
370 context_t
*context
= R700_CONTEXT(ctx
);
371 const GLvoid
*src_ptr
;
372 GLboolean mapped_named_bo
= GL_FALSE
;
376 stride
= (input
->StrideB
== 0) ? evergreen_getTypeSize(input
->Type
) * input
->Size
: input
->StrideB
;
378 /* Convert value for first element only */
379 if (input
->StrideB
== 0)
384 if (input
->BufferObj
->Name
)
386 if (!input
->BufferObj
->Pointer
)
388 ctx
->Driver
.MapBuffer(ctx
, GL_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, input
->BufferObj
);
389 mapped_named_bo
= GL_TRUE
;
392 src_ptr
= ADD_POINTERS(input
->BufferObj
->Pointer
, input
->Ptr
);
396 src_ptr
= input
->Ptr
;
399 radeonAllocDmaRegion(&context
->radeon
, &attr
->bo
, &attr
->bo_offset
,
400 sizeof(GLfloat
) * input
->Size
* count
, 32);
402 radeon_bo_map(attr
->bo
, 1);
404 dst_ptr
= (GLfloat
*)ADD_POINTERS(attr
->bo
->ptr
, attr
->bo_offset
);
406 assert(src_ptr
!= NULL
);
411 CONVERT(GLdouble
, (GLfloat
));
413 case GL_UNSIGNED_INT
:
414 CONVERT(GLuint
, UINT_TO_FLOAT
);
417 CONVERT(GLint
, INT_TO_FLOAT
);
419 case GL_UNSIGNED_SHORT
:
420 CONVERT(GLushort
, USHORT_TO_FLOAT
);
423 CONVERT(GLshort
, SHORT_TO_FLOAT
);
425 case GL_UNSIGNED_BYTE
:
426 assert(input
->Format
!= GL_BGRA
);
427 CONVERT(GLubyte
, UBYTE_TO_FLOAT
);
430 CONVERT(GLbyte
, BYTE_TO_FLOAT
);
437 radeon_bo_unmap(attr
->bo
);
441 ctx
->Driver
.UnmapBuffer(ctx
, GL_ARRAY_BUFFER
, input
->BufferObj
);
445 static void evergreenFixupIndexBuffer(struct gl_context
*ctx
, const struct _mesa_index_buffer
*mesa_ind_buf
)
447 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
451 GLboolean mapped_named_bo
= GL_FALSE
;
453 if (mesa_ind_buf
->obj
->Name
&& !mesa_ind_buf
->obj
->Pointer
)
455 ctx
->Driver
.MapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, mesa_ind_buf
->obj
);
456 mapped_named_bo
= GL_TRUE
;
457 assert(mesa_ind_buf
->obj
->Pointer
!= NULL
);
459 src_ptr
= ADD_POINTERS(mesa_ind_buf
->obj
->Pointer
, mesa_ind_buf
->ptr
);
461 if (mesa_ind_buf
->type
== GL_UNSIGNED_BYTE
)
463 GLuint size
= sizeof(GLushort
) * ((mesa_ind_buf
->count
+ 1) & ~1);
464 GLubyte
*in
= (GLubyte
*)src_ptr
;
466 radeonAllocDmaRegion(&context
->radeon
, &context
->ind_buf
.bo
,
467 &context
->ind_buf
.bo_offset
, size
, 4);
469 radeon_bo_map(context
->ind_buf
.bo
, 1);
470 assert(context
->ind_buf
.bo
->ptr
!= NULL
);
471 out
= (GLuint
*)ADD_POINTERS(context
->ind_buf
.bo
->ptr
, context
->ind_buf
.bo_offset
);
473 for (i
= 0; i
+ 1 < mesa_ind_buf
->count
; i
+= 2)
475 *out
++ = in
[i
] | in
[i
+ 1] << 16;
478 if (i
< mesa_ind_buf
->count
)
483 radeon_bo_unmap(context
->ind_buf
.bo
);
487 { /* if (mesa_ind_buf->type == GL_UNSIGNED_SHORT) */
488 GLushort
*in
= (GLushort
*)src_ptr
;
489 GLuint size
= sizeof(GLushort
) * ((mesa_ind_buf
->count
+ 1) & ~1);
491 radeonAllocDmaRegion(&context
->radeon
, &context
->ind_buf
.bo
,
492 &context
->ind_buf
.bo_offset
, size
, 4);
494 radeon_bo_map(context
->ind_buf
.bo
, 1);
495 assert(context
->ind_buf
.bo
->ptr
!= NULL
);
496 out
= (GLuint
*)ADD_POINTERS(context
->ind_buf
.bo
->ptr
, context
->ind_buf
.bo_offset
);
498 for (i
= 0; i
+ 1 < mesa_ind_buf
->count
; i
+= 2)
500 *out
++ = in
[i
] | in
[i
+ 1] << 16;
503 if (i
< mesa_ind_buf
->count
)
507 radeon_bo_unmap(context
->ind_buf
.bo
);
511 context
->ind_buf
.is_32bit
= GL_FALSE
;
512 context
->ind_buf
.count
= mesa_ind_buf
->count
;
516 ctx
->Driver
.UnmapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, mesa_ind_buf
->obj
);
520 static GLboolean
evergreen_check_fallbacks(struct gl_context
*ctx
) //same
522 if (ctx
->RenderMode
!= GL_RENDER
)
528 /* start 3d, idle, cb/db flush */
529 #define PRE_EMIT_STATE_BUFSZ 5 + 5 + 14
531 static GLuint
evergreenPredictRenderSize(struct gl_context
* ctx
,
532 const struct _mesa_prim
*prim
,
533 const struct _mesa_index_buffer
*ib
,
536 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
541 dwords
= PRE_EMIT_STATE_BUFSZ
;
543 dwords
+= nr_prims
* 18;
545 for (i
= 0; i
< nr_prims
; ++i
)
547 if (prim
[i
].start
== 0)
549 else if (prim
[i
].count
> 0xffff)
550 dwords
+= prim
[i
].count
+ 14;
552 dwords
+= ((prim
[i
].count
+ 1) / 2) + 14;
556 state_size
= radeonCountStateEmitSize(&context
->radeon
);
557 flushed
= rcommonEnsureCmdBufSpace(&context
->radeon
,
561 dwords
+= radeonCountStateEmitSize(&context
->radeon
);
563 dwords
+= state_size
;
565 radeon_print(RADEON_RENDER
, RADEON_VERBOSE
, "%s: total prediction size is %d.\n", __FUNCTION__
, dwords
);
570 static void evergreenSetupIndexBuffer(struct gl_context
*ctx
, const struct _mesa_index_buffer
*mesa_ind_buf
)
572 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
575 context
->ind_buf
.bo
= NULL
;
580 if (mesa_ind_buf
->type
== GL_UNSIGNED_INT
)
582 if (mesa_ind_buf
->type
!= GL_UNSIGNED_BYTE
)
585 const GLvoid
*src_ptr
;
587 GLboolean mapped_named_bo
= GL_FALSE
;
589 if (mesa_ind_buf
->obj
->Name
&& !mesa_ind_buf
->obj
->Pointer
)
591 ctx
->Driver
.MapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, mesa_ind_buf
->obj
);
592 assert(mesa_ind_buf
->obj
->Pointer
!= NULL
);
593 mapped_named_bo
= GL_TRUE
;
596 src_ptr
= ADD_POINTERS(mesa_ind_buf
->obj
->Pointer
, mesa_ind_buf
->ptr
);
598 const GLuint size
= mesa_ind_buf
->count
* getTypeSize(mesa_ind_buf
->type
);
600 radeonAllocDmaRegion(&context
->radeon
, &context
->ind_buf
.bo
,
601 &context
->ind_buf
.bo_offset
, size
, 4);
602 radeon_bo_map(context
->ind_buf
.bo
, 1);
603 assert(context
->ind_buf
.bo
->ptr
!= NULL
);
604 dst_ptr
= ADD_POINTERS(context
->ind_buf
.bo
->ptr
, context
->ind_buf
.bo_offset
);
606 memcpy(dst_ptr
, src_ptr
, size
);
608 radeon_bo_unmap(context
->ind_buf
.bo
);
609 context
->ind_buf
.is_32bit
= (mesa_ind_buf
->type
== GL_UNSIGNED_INT
);
610 context
->ind_buf
.count
= mesa_ind_buf
->count
;
614 ctx
->Driver
.UnmapBuffer(ctx
, GL_ELEMENT_ARRAY_BUFFER
, mesa_ind_buf
->obj
);
619 evergreenFixupIndexBuffer(ctx
, mesa_ind_buf
);
623 static void evergreenAlignDataToDword(struct gl_context
*ctx
,
624 const struct gl_client_array
*input
,
626 struct StreamDesc
*attr
)
628 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
629 const int dst_stride
= (input
->StrideB
+ 3) & ~3;
630 const int size
= getTypeSize(input
->Type
) * input
->Size
* count
;
631 GLboolean mapped_named_bo
= GL_FALSE
;
633 radeonAllocDmaRegion(&context
->radeon
, &attr
->bo
, &attr
->bo_offset
, size
, 32);
635 radeon_bo_map(attr
->bo
, 1);
637 if (!input
->BufferObj
->Pointer
)
639 ctx
->Driver
.MapBuffer(ctx
, GL_ARRAY_BUFFER
, GL_READ_ONLY_ARB
, input
->BufferObj
);
640 mapped_named_bo
= GL_TRUE
;
644 GLvoid
*src_ptr
= ADD_POINTERS(input
->BufferObj
->Pointer
, input
->Ptr
);
645 GLvoid
*dst_ptr
= ADD_POINTERS(attr
->bo
->ptr
, attr
->bo_offset
);
648 for (i
= 0; i
< count
; ++i
)
650 memcpy(dst_ptr
, src_ptr
, input
->StrideB
);
651 src_ptr
+= input
->StrideB
;
652 dst_ptr
+= dst_stride
;
656 radeon_bo_unmap(attr
->bo
);
659 ctx
->Driver
.UnmapBuffer(ctx
, GL_ARRAY_BUFFER
, input
->BufferObj
);
662 attr
->stride
= dst_stride
;
665 static void evergreenSetupStreams(struct gl_context
*ctx
, const struct gl_client_array
*input
[], int count
)
667 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
672 EVERGREEN_STATECHANGE(context
, vtx
);
674 for(index
= 0; index
< context
->nNumActiveAos
; index
++)
676 struct radeon_aos
*aos
= &context
->radeon
.tcl
.aos
[index
];
677 i
= context
->stream_desc
[index
].element
;
679 stride
= (input
[i
]->StrideB
== 0) ? getTypeSize(input
[i
]->Type
) * input
[i
]->Size
: input
[i
]->StrideB
;
681 if (input
[i
]->Type
== GL_DOUBLE
|| input
[i
]->Type
== GL_UNSIGNED_INT
|| input
[i
]->Type
== GL_INT
683 || getTypeSize(input
[i
]->Type
) != 4
687 evergreenConvertAttrib(ctx
, count
, input
[i
], &context
->stream_desc
[index
]);
691 if (input
[i
]->BufferObj
->Name
)
693 context
->stream_desc
[index
].stride
= input
[i
]->StrideB
;
694 context
->stream_desc
[index
].bo_offset
= (intptr_t) input
[i
]->Ptr
;
695 context
->stream_desc
[index
].bo
= get_radeon_buffer_object(input
[i
]->BufferObj
)->bo
;
696 context
->stream_desc
[index
].is_named_bo
= GL_TRUE
;
701 int local_count
= count
;
704 if (input
[i
]->StrideB
== 0)
706 size
= getTypeSize(input
[i
]->Type
) * input
[i
]->Size
;
711 size
= getTypeSize(input
[i
]->Type
) * input
[i
]->Size
* local_count
;
714 radeonAllocDmaRegion(&context
->radeon
, &context
->stream_desc
[index
].bo
,
715 &context
->stream_desc
[index
].bo_offset
, size
, 32);
717 radeon_bo_map(context
->stream_desc
[index
].bo
, 1);
718 assert(context
->stream_desc
[index
].bo
->ptr
!= NULL
);
721 dst
= (uint32_t *)ADD_POINTERS(context
->stream_desc
[index
].bo
->ptr
,
722 context
->stream_desc
[index
].bo_offset
);
724 switch (context
->stream_desc
[index
].dwords
)
727 radeonEmitVec4(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
);
730 radeonEmitVec8(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
);
733 radeonEmitVec12(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
);
736 radeonEmitVec16(dst
, input
[i
]->Ptr
, input
[i
]->StrideB
, local_count
);
743 radeon_bo_unmap(context
->stream_desc
[index
].bo
);
747 aos
->count
= context
->stream_desc
[index
].stride
== 0 ? 1 : count
;
748 aos
->stride
= context
->stream_desc
[index
].stride
/ sizeof(float);
749 aos
->components
= context
->stream_desc
[index
].dwords
;
750 aos
->bo
= context
->stream_desc
[index
].bo
;
751 aos
->offset
= context
->stream_desc
[index
].bo_offset
;
753 if(context
->stream_desc
[index
].is_named_bo
)
755 radeon_cs_space_add_persistent_bo(context
->radeon
.cmdbuf
.cs
,
756 context
->stream_desc
[index
].bo
,
757 RADEON_GEM_DOMAIN_GTT
, 0);
761 ret
= radeon_cs_space_check_with_bo(context
->radeon
.cmdbuf
.cs
,
762 first_elem(&context
->radeon
.dma
.reserved
)->bo
,
763 RADEON_GEM_DOMAIN_GTT
, 0);
766 static void evergreenFreeData(struct gl_context
*ctx
)
768 /* Need to zero tcl.aos[n].bo and tcl.elt_dma_bo
769 * to prevent double unref in radeonReleaseArrays
770 * called during context destroy
772 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
776 for (i
= 0; i
< context
->nNumActiveAos
; i
++)
778 if (!context
->stream_desc
[i
].is_named_bo
)
780 radeon_bo_unref(context
->stream_desc
[i
].bo
);
782 context
->radeon
.tcl
.aos
[i
].bo
= NULL
;
785 if(context
->vp_Constbo
!= NULL
)
787 radeon_bo_unref(context
->vp_Constbo
);
788 context
->vp_Constbo
= NULL
;
790 if(context
->fp_Constbo
!= NULL
)
792 radeon_bo_unref(context
->fp_Constbo
);
793 context
->fp_Constbo
= NULL
;
796 if (context
->ind_buf
.bo
!= NULL
)
798 radeon_bo_unref(context
->ind_buf
.bo
);
802 static GLboolean
evergreenTryDrawPrims(struct gl_context
*ctx
,
803 const struct gl_client_array
*arrays
[],
804 const struct _mesa_prim
*prim
,
806 const struct _mesa_index_buffer
*ib
,
810 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
811 radeonContextPtr radeon
= &context
->radeon
;
813 struct radeon_renderbuffer
*rrb
;
816 _mesa_update_state( ctx
);
818 if (evergreen_check_fallbacks(ctx
))
821 _tnl_UpdateFixedFunctionProgram(ctx
);
822 evergreenSetVertexFormat(ctx
, arrays
, max_index
+ 1);
825 /* shaders need to be updated before buffers are validated */
826 evergreenUpdateShaders(ctx
);
827 if (!evergreenValidateBuffers(ctx
))
830 /* always emit CB base to prevent
831 * lock ups on some chips.
833 EVERGREEN_STATECHANGE(context
, cb
);
834 /* mark vtx as dirty since it changes per-draw */
835 EVERGREEN_STATECHANGE(context
, vtx
);
837 evergreenSetScissor(context
);
839 evergreenSetupVertexProgram(ctx
);
840 evergreenSetupFragmentProgram(ctx
);
841 evergreenUpdateShaderStates(ctx
);
843 GLuint emit_end
= evergreenPredictRenderSize(ctx
, prim
, ib
, nr_prims
)
844 + context
->radeon
.cmdbuf
.cs
->cdw
;
846 /* evergreenPredictRenderSize will call radeonReleaseDmaRegions, so update VP/FP const buf after it. */
847 evergreenSetupVPconstants(ctx
);
848 evergreenSetupFPconstants(ctx
);
850 evergreenSetupIndexBuffer(ctx
, ib
);
852 evergreenSetupStreams(ctx
, arrays
, max_index
+ 1);
854 radeonEmitState(radeon
);
856 radeon_debug_add_indent();
858 for (i
= 0; i
< nr_prims
; ++i
)
860 if (context
->ind_buf
.bo
)
861 evergreenRunRenderPrimitive(ctx
,
863 prim
[i
].start
+ prim
[i
].count
,
867 evergreenRunRenderPrimitiveImmediate(ctx
,
869 prim
[i
].start
+ prim
[i
].count
,
873 radeon_debug_remove_indent();
875 /* Flush render op cached for last several quads. */
876 /* XXX drm should handle this in fence submit */
878 //evergreeWaitForIdleClean(context);
880 rrb
= radeon_get_colorbuffer(&context
->radeon
);
882 r700SyncSurf(context
, rrb
->bo
, 0, RADEON_GEM_DOMAIN_VRAM
,
883 CB_ACTION_ENA_bit
| (1 << (id
+ 6)));
885 rrb
= radeon_get_depthbuffer(&context
->radeon
);
887 r700SyncSurf(context
, rrb
->bo
, 0, RADEON_GEM_DOMAIN_VRAM
,
888 DB_ACTION_ENA_bit
| DB_DEST_BASE_ENA_bit
);
890 evergreenFreeData(ctx
);
892 if (emit_end
< context
->radeon
.cmdbuf
.cs
->cdw
)
894 WARN_ONCE("Rendering was %d commands larger than predicted size."
895 " We might overflow command buffer.\n", context
->radeon
.cmdbuf
.cs
->cdw
- emit_end
);
901 static void evergreenDrawPrims(struct gl_context
*ctx
,
902 const struct gl_client_array
*arrays
[],
903 const struct _mesa_prim
*prim
,
905 const struct _mesa_index_buffer
*ib
,
906 GLboolean index_bounds_valid
,
910 GLboolean retval
= GL_FALSE
;
912 context_t
*context
= EVERGREEN_CONTEXT(ctx
);
913 radeonContextPtr radeon
= &context
->radeon
;
914 radeon_prepare_render(radeon
);
916 /* This check should get folded into just the places that
917 * min/max index are really needed.
919 if (!vbo_all_varyings_in_vbos(arrays
)) {
920 if (!index_bounds_valid
)
921 vbo_get_minmax_index(ctx
, prim
, ib
, &min_index
, &max_index
);
922 /* do we want to rebase, minimizes the
923 * amount of data to upload? */
925 vbo_rebase_prims( ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
, evergreenDrawPrims
);
929 /* Make an attempt at drawing */
930 retval
= evergreenTryDrawPrims(ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
);
932 /* If failed run tnl pipeline - it should take care of fallbacks */
934 _swsetup_Wakeup(ctx
);
935 _tnl_draw_prims(ctx
, arrays
, prim
, nr_prims
, ib
, min_index
, max_index
);
939 void evergreenInitDraw(struct gl_context
*ctx
)
941 struct vbo_context
*vbo
= vbo_context(ctx
);
944 vbo
->draw_prims
= evergreenDrawPrims
;