Re-enable fallbacks.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_render.c
1 /**************************************************************************
2
3 Copyright (C) 2004 Nicolai Haehnle.
4
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Nicolai Haehnle <prefect_@gmx.net>
31 */
32
33 #include "glheader.h"
34 #include "state.h"
35 #include "imports.h"
36 #include "enums.h"
37 #include "macros.h"
38 #include "context.h"
39 #include "dd.h"
40 #include "simple_list.h"
41
42 #include "api_arrayelt.h"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
45 #include "array_cache/acache.h"
46 #include "tnl/tnl.h"
47 #include "tnl/t_vp_build.h"
48
49 #include "radeon_reg.h"
50 #include "radeon_macros.h"
51 #include "radeon_ioctl.h"
52 #include "radeon_state.h"
53 #include "r300_context.h"
54 #include "r300_ioctl.h"
55 #include "r300_state.h"
56 #include "r300_reg.h"
57 #include "r300_program.h"
58 #include "r300_tex.h"
59 #include "r300_maos.h"
60 #include "r300_emit.h"
61
62 extern int future_hw_tcl_on;
63
64 /**********************************************************************
65 * Hardware rasterization
66 *
67 * When we fell back to software TCL, we still try to use the
68 * rasterization hardware for rendering.
69 **********************************************************************/
70
71 static int r300_get_primitive_type(r300ContextPtr rmesa, GLcontext *ctx, int prim)
72 {
73 int type=-1;
74
75 switch (prim & PRIM_MODE_MASK) {
76 case GL_POINTS:
77 type=R300_VAP_VF_CNTL__PRIM_POINTS;
78 break;
79 case GL_LINES:
80 type=R300_VAP_VF_CNTL__PRIM_LINES;
81 break;
82 case GL_LINE_STRIP:
83 type=R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
84 break;
85 case GL_LINE_LOOP:
86 type=R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
87 break;
88 case GL_TRIANGLES:
89 type=R300_VAP_VF_CNTL__PRIM_TRIANGLES;
90 break;
91 case GL_TRIANGLE_STRIP:
92 type=R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP;
93 break;
94 case GL_TRIANGLE_FAN:
95 type=R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN;
96 break;
97 case GL_QUADS:
98 type=R300_VAP_VF_CNTL__PRIM_QUADS;
99 break;
100 case GL_QUAD_STRIP:
101 type=R300_VAP_VF_CNTL__PRIM_QUAD_STRIP;
102 break;
103 case GL_POLYGON:
104 type=R300_VAP_VF_CNTL__PRIM_POLYGON;
105 break;
106 default:
107 fprintf(stderr, "%s:%s Do not know how to handle primitive %02x - help me !\n",
108 __FILE__, __FUNCTION__,
109 prim & PRIM_MODE_MASK);
110 return -1;
111 break;
112 }
113 return type;
114 }
115
116 static int r300_get_num_verts(r300ContextPtr rmesa,
117 GLcontext *ctx,
118 int num_verts,
119 int prim)
120 {
121 int verts_off=0;
122 char *name="UNKNOWN";
123
124 switch (prim & PRIM_MODE_MASK) {
125 case GL_POINTS:
126 name="P";
127 verts_off = 0;
128 break;
129 case GL_LINES:
130 name="L";
131 verts_off = num_verts % 2;
132 break;
133 case GL_LINE_STRIP:
134 name="LS";
135 if(num_verts < 2)
136 verts_off = num_verts;
137 break;
138 case GL_LINE_LOOP:
139 name="LL";
140 if(num_verts < 2)
141 verts_off = num_verts;
142 break;
143 case GL_TRIANGLES:
144 name="T";
145 verts_off = num_verts % 3;
146 break;
147 case GL_TRIANGLE_STRIP:
148 name="TS";
149 if(num_verts < 3)
150 verts_off = num_verts;
151 break;
152 case GL_TRIANGLE_FAN:
153 name="TF";
154 if(num_verts < 3)
155 verts_off = num_verts;
156 break;
157 case GL_QUADS:
158 name="Q";
159 verts_off = num_verts % 4;
160 break;
161 case GL_QUAD_STRIP:
162 name="QS";
163 if(num_verts < 4)
164 verts_off = num_verts;
165 else
166 verts_off = num_verts % 2;
167 break;
168 case GL_POLYGON:
169 name="P";
170 if(num_verts < 3)
171 verts_off = num_verts;
172 break;
173 default:
174 fprintf(stderr, "%s:%s Do not know how to handle primitive %02x - help me !\n",
175 __FILE__, __FUNCTION__,
176 prim & PRIM_MODE_MASK);
177 return -1;
178 break;
179 }
180
181 if (RADEON_DEBUG & DEBUG_VERTS) {
182 if (num_verts - verts_off == 0) {
183 WARN_ONCE("user error: Need more than %d vertices to draw primitive %s !\n", num_verts, name);
184 return 0;
185 }
186
187 if (verts_off > 0) {
188 WARN_ONCE("user error: %d is not a valid number of vertices for primitive %s !\n", num_verts, name);
189 }
190 }
191
192 return num_verts - verts_off;
193 }
194
195 /* This function compiles GL context into state registers that
196 describe data routing inside of R300 pipeline.
197
198 In particular, it programs input_route, output_vtx_fmt, texture
199 unit configuration and gb_output_vtx_fmt
200
201 This function encompasses setup_AOS() from r300_lib.c
202 */
203
204
205
206
207 /* Immediate implementation - vertex data is sent via command stream */
208
209 static GLfloat default_vector[4]={0.0, 0.0, 0.0, 1.0};
210
211 #define output_vector(v, i) { \
212 int _i; \
213 for(_i=0;_i<v->size;_i++){ \
214 if(VB->Elts){ \
215 efloat(VEC_ELT(v, GLfloat, VB->Elts[i])[_i]); \
216 }else{ \
217 efloat(VEC_ELT(v, GLfloat, i)[_i]); \
218 } \
219 } \
220 for(_i=v->size;_i<4;_i++){ \
221 efloat(default_vector[_i]); \
222 } \
223 }
224
225 /* Immediate implementation - vertex data is sent via command stream */
226
227 static void r300_render_immediate_primitive(r300ContextPtr rmesa,
228 GLcontext *ctx,
229 int start,
230 int end,
231 int prim)
232 {
233 TNLcontext *tnl = TNL_CONTEXT(ctx);
234 struct vertex_buffer *VB = &tnl->vb;
235 GLuint i, render_inputs;
236 int k, type, num_verts;
237 LOCAL_VARS
238
239 type=r300_get_primitive_type(rmesa, ctx, prim);
240 num_verts=r300_get_num_verts(rmesa, ctx, end-start, prim);
241
242 #if 0
243 fprintf(stderr,"ObjPtr: size=%d stride=%d\n",
244 VB->ObjPtr->size, VB->ObjPtr->stride);
245 fprintf(stderr,"ColorPtr[0]: size=%d stride=%d\n",
246 VB->ColorPtr[0]->size, VB->ColorPtr[0]->stride);
247 fprintf(stderr,"TexCoordPtr[0]: size=%d stride=%d\n",
248 VB->TexCoordPtr[0]->size, VB->TexCoordPtr[0]->stride);
249 #endif
250
251 if(type<0 || num_verts <= 0)return;
252
253 if(!VB->ObjPtr){
254 WARN_ONCE("FIXME: Don't know how to handle GL_ARB_vertex_buffer_object correctly\n");
255 return;
256 }
257 /* A packet cannot have more than 16383 data words.. */
258 if((num_verts*4*rmesa->state.aos_count)>16380){
259 WARN_ONCE("Too many vertices to paint. Fix me !\n");
260 return;
261 }
262
263 //fprintf(stderr, "aos_count=%d start=%d end=%d\n", rmesa->state.aos_count, start, end);
264
265 if(rmesa->state.aos_count==0){
266 WARN_ONCE("Aeiee ! aos_count==0, while it shouldn't. Skipping rendering\n");
267 return;
268 }
269
270 render_inputs = rmesa->state.render_inputs;
271
272 if(!render_inputs){
273 WARN_ONCE("Aeiee ! render_inputs==0. Skipping rendering.\n");
274 return;
275 }
276
277
278 start_immediate_packet(num_verts, type, 4*rmesa->state.aos_count);
279
280 for(i=start;i<start+num_verts;i++){
281 #if 0
282 fprintf(stderr, "* (%f %f %f %f) (%f %f %f %f)\n",
283 VEC_ELT(VB->ObjPtr, GLfloat, i)[0],
284 VEC_ELT(VB->ObjPtr, GLfloat, i)[1],
285 VEC_ELT(VB->ObjPtr, GLfloat, i)[2],
286 VEC_ELT(VB->ObjPtr, GLfloat, i)[3],
287
288 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[0],
289 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[1],
290 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[2],
291 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[3]
292 );
293 #endif
294
295
296 /* coordinates */
297 if(render_inputs & _TNL_BIT_POS)
298 output_vector(VB->ObjPtr, i);
299 if(render_inputs & _TNL_BIT_NORMAL)
300 output_vector(VB->NormalPtr, i);
301
302 /* color components */
303 if(render_inputs & _TNL_BIT_COLOR0)
304 output_vector(VB->ColorPtr[0], i);
305 if(render_inputs & _TNL_BIT_COLOR1)
306 output_vector(VB->SecondaryColorPtr[0], i);
307
308 /* if(render_inputs & _TNL_BIT_FOG) // Causes lock ups when immediate mode is on
309 output_vector(VB->FogCoordPtr, i);*/
310
311 /* texture coordinates */
312 for(k=0;k < ctx->Const.MaxTextureUnits;k++)
313 if(render_inputs & (_TNL_BIT_TEX0<<k))
314 output_vector(VB->TexCoordPtr[k], i);
315
316 if(render_inputs & _TNL_BIT_INDEX)
317 output_vector(VB->IndexPtr[0], i);
318 if(render_inputs & _TNL_BIT_POINTSIZE)
319 output_vector(VB->PointSizePtr, i);
320 }
321
322 }
323
324
325 static GLboolean r300_run_immediate_render(GLcontext *ctx,
326 struct tnl_pipeline_stage *stage)
327 {
328 r300ContextPtr rmesa = R300_CONTEXT(ctx);
329 TNLcontext *tnl = TNL_CONTEXT(ctx);
330 struct vertex_buffer *VB = &tnl->vb;
331 GLuint i;
332 LOCAL_VARS
333
334
335 /* Update texture state - needs to be done only when actually changed..
336 All the time for now.. */
337
338
339 if (RADEON_DEBUG == DEBUG_PRIMS)
340 fprintf(stderr, "%s\n", __FUNCTION__);
341
342 #if 1 /* we need this, somehow */
343 /* Flush state - make sure command buffer is nice and large */
344 r300Flush(ctx);
345 /* Make sure we have enough space */
346 #else
347 /* Count is very imprecize, but should be good upper bound */
348 r300EnsureCmdBufSpace(rmesa, rmesa->hw.max_state_size + 4+2+30
349 +VB->PrimitiveCount*(1+8)+VB->Count*4*rmesa->state.texture.tc_count+4, __FUNCTION__);
350 #endif
351
352 /* needed before starting 3d operation .. */
353 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
354 e32(0x0000000a);
355
356 reg_start(0x4f18,0);
357 e32(0x00000003);
358
359
360 #if 0 /* looks like the Z offset issue got fixed */
361 rmesa->hw.vte.cmd[1] = R300_VPORT_X_SCALE_ENA
362 | R300_VPORT_X_OFFSET_ENA
363 | R300_VPORT_Y_SCALE_ENA
364 | R300_VPORT_Y_OFFSET_ENA
365 | R300_VTX_W0_FMT;
366 R300_STATECHANGE(rmesa, vte);
367 #endif
368
369
370
371 /* Magic register - note it is right after 20b0 */
372
373
374 if(rmesa->state.texture.tc_count>0){
375 reg_start(0x20b4,0);
376 e32(0x0000000c);
377
378 }
379
380 r300EmitState(rmesa);
381
382 /* Setup INPUT_ROUTE and INPUT_CNTL */
383 r300EmitArrays(ctx, GL_TRUE);
384
385 /* Why do we need this for immediate mode?? Vertex processor needs it to know proper regs */
386 // r300EmitLOAD_VBPNTR(rmesa, 0);
387 /* Okay, it seems I misunderstood something, EmitAOS does the same thing */
388 r300EmitAOS(rmesa, rmesa->state.aos_count, 0);
389
390 for(i=0; i < VB->PrimitiveCount; i++){
391 GLuint prim = VB->Primitive[i].mode;
392 GLuint start = VB->Primitive[i].start;
393 GLuint length = VB->Primitive[i].count;
394
395 r300_render_immediate_primitive(rmesa, ctx, start, start + length, prim);
396 }
397
398 /* This sequence is required after any 3d drawing packet
399 I suspect it work arounds a bug (or deficiency) in hardware */
400
401 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
402 e32(0x0000000a);
403
404 reg_start(0x4f18,0);
405 e32(0x00000003);
406
407 return GL_FALSE;
408 }
409
410
411 /* vertex buffer implementation */
412
413 static void inline fire_EB(PREFIX unsigned long addr, int vertex_count, int type, int elt_size)
414 {
415 LOCAL_VARS
416 unsigned long addr_a;
417 unsigned long t_addr;
418 unsigned long magic_1, magic_2;
419 GLcontext *ctx;
420 ctx = rmesa->radeon.glCtx;
421
422 assert(elt_size == 2 || elt_size == 4);
423
424 if(addr & (elt_size-1)){
425 WARN_ONCE("Badly aligned buffer\n");
426 return ;
427 }
428 #ifdef OPTIMIZE_ELTS
429 addr_a = 0;
430
431 magic_1 = (addr % 32) / 4;
432 t_addr = addr & (~0x1d);
433 magic_2 = (vertex_count + 1 + (t_addr & 0x2)) / 2 + magic_1;
434
435 check_space(6);
436
437 start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, 0);
438 if(elt_size == 4){
439 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count<<16) | type | R300_VAP_VF_CNTL__INDEX_SIZE_32bit);
440 } else {
441 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count<<16) | type);
442 }
443
444 start_packet3(RADEON_CP_PACKET3_INDX_BUFFER, 2);
445 if(elt_size == 4){
446 e32(R300_EB_UNK1 | (0 << 16) | R300_EB_UNK2);
447 e32(addr /*& 0xffffffe3*/);
448 } else {
449 e32(R300_EB_UNK1 | (magic_1 << 16) | R300_EB_UNK2);
450 e32(t_addr);
451 }
452
453 if(elt_size == 4){
454 e32(vertex_count /*+ addr_a/4*/); /* Total number of dwords needed? */
455 } else {
456 e32(magic_2); /* Total number of dwords needed? */
457 }
458 //cp_delay(PASS_PREFIX 1);
459 #if 0
460 fprintf(stderr, "magic_1 %d\n", magic_1);
461 fprintf(stderr, "t_addr %x\n", t_addr);
462 fprintf(stderr, "magic_2 %d\n", magic_2);
463 exit(1);
464 #endif
465 #else
466 (void)magic_2, (void)magic_1, (void)t_addr;
467
468 addr_a = 0;
469
470 check_space(6);
471
472 start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, 0);
473 if(elt_size == 4){
474 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count<<16) | type | R300_VAP_VF_CNTL__INDEX_SIZE_32bit);
475 } else {
476 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count<<16) | type);
477 }
478
479 start_packet3(RADEON_CP_PACKET3_INDX_BUFFER, 2);
480 e32(R300_EB_UNK1 | (0 << 16) | R300_EB_UNK2);
481 e32(addr /*& 0xffffffe3*/);
482
483 if(elt_size == 4){
484 e32(vertex_count /*+ addr_a/4*/); /* Total number of dwords needed? */
485 } else {
486 e32((vertex_count+1)/2 /*+ addr_a/4*/); /* Total number of dwords needed? */
487 }
488 //cp_delay(PASS_PREFIX 1);
489 #endif
490 }
491
492 static void r300_render_vb_primitive(r300ContextPtr rmesa,
493 GLcontext *ctx,
494 int start,
495 int end,
496 int prim)
497 {
498 int type, num_verts;
499 LOCAL_VARS
500
501 type=r300_get_primitive_type(rmesa, ctx, prim);
502 num_verts=r300_get_num_verts(rmesa, ctx, end-start, prim);
503
504 if(type<0 || num_verts <= 0)return;
505
506 if(rmesa->state.Elts){
507 r300EmitAOS(rmesa, rmesa->state.aos_count, 0);
508 #if 0
509 int i;
510 start_index32_packet(num_verts, type);
511 for(i=0; i < num_verts; i++)
512 e32(rmesa->state.Elts[start+i]); /* start ? */
513 #else
514 WARN_ONCE("Rendering with elt buffers\n");
515 if(num_verts == 1){
516 start_index32_packet(num_verts, type);
517 e32(rmesa->state.Elts[start]);
518 return;
519 }
520
521 if(num_verts > 65535){ /* not implemented yet */
522 WARN_ONCE("Too many elts\n");
523 return;
524 }
525 r300EmitElts(ctx, rmesa->state.Elts+start, num_verts, 4);
526 fire_EB(PASS_PREFIX GET_START(&(rmesa->state.elt_dma)), num_verts, type, 4);
527 #endif
528 }else{
529 r300EmitAOS(rmesa, rmesa->state.aos_count, start);
530 fire_AOS(PASS_PREFIX num_verts, type);
531 }
532 }
533
534 static GLboolean r300_run_vb_render(GLcontext *ctx,
535 struct tnl_pipeline_stage *stage)
536 {
537 r300ContextPtr rmesa = R300_CONTEXT(ctx);
538 TNLcontext *tnl = TNL_CONTEXT(ctx);
539 struct vertex_buffer *VB = &tnl->vb;
540 int i;
541 LOCAL_VARS
542
543 if (RADEON_DEBUG & DEBUG_PRIMS)
544 fprintf(stderr, "%s\n", __FUNCTION__);
545
546
547 r300UpdateShaders(rmesa);
548
549 r300ReleaseArrays(ctx);
550 r300EmitArrays(ctx, GL_FALSE);
551
552 r300UpdateShaderStates(rmesa);
553 // LOCK_HARDWARE(&(rmesa->radeon));
554
555 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
556 e32(0x0000000a);
557
558 reg_start(0x4f18,0);
559 e32(0x00000003);
560 r300EmitState(rmesa);
561
562 rmesa->state.Elts = VB->Elts;
563
564 for(i=0; i < VB->PrimitiveCount; i++){
565 GLuint prim = VB->Primitive[i].mode;
566 GLuint start = VB->Primitive[i].start;
567 GLuint length = VB->Primitive[i].count;
568
569 r300_render_vb_primitive(rmesa, ctx, start, start + length, prim);
570 }
571
572 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
573 e32(0x0000000a);
574
575 reg_start(0x4f18,0);
576 e32(0x00000003);
577
578 #ifdef USER_BUFFERS
579 r300UseArrays(ctx);
580 #endif
581 // end_3d(PASS_PREFIX_VOID);
582
583 /* Flush state - we are done drawing.. */
584 // r300FlushCmdBufLocked(rmesa, __FUNCTION__);
585 // radeonWaitForIdleLocked(&(rmesa->radeon));
586
587 // UNLOCK_HARDWARE(&(rmesa->radeon));
588 return GL_FALSE;
589 }
590
591 #ifdef RADEON_VTXFMT_A
592
593 static void r300_render_vb_primitive_vtxfmt_a(r300ContextPtr rmesa,
594 GLcontext *ctx,
595 int start,
596 int end,
597 int prim)
598 {
599 int type, num_verts;
600 radeonScreenPtr rsp=rmesa->radeon.radeonScreen;
601 LOCAL_VARS
602 TNLcontext *tnl = TNL_CONTEXT(ctx);
603 struct vertex_buffer *VB = &tnl->vb;
604 int i;
605
606 type=r300_get_primitive_type(rmesa, ctx, prim);
607 num_verts=r300_get_num_verts(rmesa, ctx, end-start, prim);
608
609 if(type<0 || num_verts <= 0)return;
610
611 if(rmesa->state.VB.Elts){
612 r300EmitAOS(rmesa, rmesa->state.aos_count, /*0*/start);
613 #if 0
614 start_index32_packet(num_verts, type);
615 for(i=0; i < num_verts; i++)
616 e32(((unsigned long *)rmesa->state.VB.Elts)[i]/*rmesa->state.Elts[start+i]*/); /* start ? */
617 #else
618 WARN_ONCE("Rendering with elt buffers\n");
619 if(num_verts == 1){
620 //start_index32_packet(num_verts, type);
621 //e32(rmesa->state.Elts[start]);
622 return;
623 }
624
625 if(num_verts > 65535){ /* not implemented yet */
626 WARN_ONCE("Too many elts\n");
627 return;
628 }
629
630 r300EmitElts(ctx, rmesa->state.VB.Elts, num_verts, rmesa->state.VB.elt_size);
631 fire_EB(PASS_PREFIX rmesa->state.elt_dma.aos_offset, num_verts, type, rmesa->state.VB.elt_size);
632 #endif
633 }else{
634 r300EmitAOS(rmesa, rmesa->state.aos_count, start);
635 fire_AOS(PASS_PREFIX num_verts, type);
636 }
637 }
638
639 void dump_array(struct r300_dma_region *rvb, int count)
640 {
641 int *out = (int *)(rvb->address + rvb->start);
642 int i, ci;
643
644 for (i=0; i < count; i++) {
645 fprintf(stderr, "{");
646 if (rvb->aos_format == AOS_FORMAT_FLOAT)
647 for (ci=0; ci < rvb->aos_size; ci++)
648 fprintf(stderr, "%f ", ((float *)out)[ci]);
649 else
650 for (ci=0; ci < rvb->aos_size; ci++)
651 fprintf(stderr, "%d ", ((unsigned char *)out)[ci]);
652 fprintf(stderr, "}");
653
654 out += rvb->aos_stride;
655 }
656
657 fprintf(stderr, "\n");
658 }
659
660 void dump_dt(struct dt *dt, int count)
661 {
662 int *out = dt->data;
663 int i, ci;
664
665 fprintf(stderr, "base at %p ", out);
666
667 for (i=0; i < count; i++){
668 fprintf(stderr, "{");
669 if (dt->type == GL_FLOAT)
670 for (ci=0; ci < dt->size; ci++)
671 fprintf(stderr, "%f ", ((float *)out)[ci]);
672 else
673 for (ci=0; ci < dt->size; ci++)
674 fprintf(stderr, "%d ", ((unsigned char *)out)[ci]);
675 fprintf(stderr, "}");
676
677 out = (char *)out + dt->stride;
678 }
679
680 fprintf(stderr, "\n");
681 }
682
683 /*static */GLboolean r300_run_vb_render_vtxfmt_a(GLcontext *ctx,
684 struct tnl_pipeline_stage *stage)
685 {
686 r300ContextPtr rmesa = R300_CONTEXT(ctx);
687 //TNLcontext *tnl = TNL_CONTEXT(ctx);
688 struct radeon_vertex_buffer *VB = &rmesa->state.VB; //&tnl->vb;
689 int i, j;
690 LOCAL_VARS
691
692 if (RADEON_DEBUG & DEBUG_PRIMS)
693 fprintf(stderr, "%s\n", __FUNCTION__);
694
695 if (rmesa->state.VB.LockCount == 0) {
696 r300ReleaseArrays(ctx);
697 r300EmitArraysVtx(ctx, GL_FALSE);
698
699 r300UpdateShaderStates(rmesa);
700 } else {
701 /* TODO: Figure out why do we need these. */
702 R300_STATECHANGE(rmesa, vir[0]);
703 R300_STATECHANGE(rmesa, vir[1]);
704 R300_STATECHANGE(rmesa, vic);
705 R300_STATECHANGE(rmesa, vof);
706
707 #if 0
708 fprintf(stderr, "dt:\n");
709 for(i=0; i < VERT_ATTRIB_MAX; i++){
710 fprintf(stderr, "dt %d:", i);
711 dump_dt(&rmesa->state.VB.AttribPtr[i], VB->Count);
712 }
713
714 fprintf(stderr, "before:\n");
715 for(i=0; i < rmesa->state.aos_count; i++){
716 fprintf(stderr, "aos %d:", i);
717 dump_array(&rmesa->state.aos[i], VB->Count);
718 }
719 #endif
720 #if 0
721 r300ReleaseArrays(ctx);
722 r300EmitArraysVtx(ctx, GL_FALSE);
723
724 fprintf(stderr, "after:\n");
725 for(i=0; i < rmesa->state.aos_count; i++){
726 fprintf(stderr, "aos %d:", i);
727 dump_array(&rmesa->state.aos[i], VB->Count);
728 }
729 #endif
730 }
731
732 // LOCK_HARDWARE(&(rmesa->radeon));
733
734 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
735 e32(0x0000000a);
736
737 reg_start(0x4f18,0);
738 e32(0x00000003);
739 #if 0
740 reg_start(R300_VAP_PVS_WAITIDLE,0);
741 e32(0x00000000);
742 #endif
743 r300EmitState(rmesa);
744
745 for(i=0; i < VB->PrimitiveCount; i++){
746 GLuint prim = VB->Primitive[i].mode;
747 GLuint start = VB->Primitive[i].start;
748 GLuint length = VB->Primitive[i].count;
749
750 r300_render_vb_primitive_vtxfmt_a(rmesa, ctx, start, start + length, prim);
751 }
752
753 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
754 e32(0x0000000a/*0x2*/);
755
756 reg_start(0x4f18,0);
757 e32(0x00000003/*0x1*/);
758
759 #ifdef USER_BUFFERS
760 r300UseArrays(ctx);
761 #endif
762 // end_3d(PASS_PREFIX_VOID);
763
764 /* Flush state - we are done drawing.. */
765 // r300FlushCmdBufLocked(rmesa, __FUNCTION__);
766 // radeonWaitForIdleLocked(&(rmesa->radeon));
767
768 // UNLOCK_HARDWARE(&(rmesa->radeon));
769 return GL_FALSE;
770 }
771 #endif
772
773 #define FALLBACK_IF(expr) \
774 do { \
775 if (expr) { \
776 if (1 || RADEON_DEBUG & DEBUG_FALLBACKS) \
777 WARN_ONCE("fallback:%s\n", #expr); \
778 return GL_TRUE; \
779 } \
780 } while(0)
781
782 GLboolean r300Fallback(GLcontext *ctx)
783 {
784
785 FALLBACK_IF(ctx->RenderMode != GL_RENDER); // We do not do SELECT or FEEDBACK (yet ?)
786
787 #if 0 /* These should work now.. */
788 FALLBACK_IF(ctx->Color.DitherFlag);
789 FALLBACK_IF(ctx->Color.AlphaEnabled); // GL_ALPHA_TEST
790 FALLBACK_IF(ctx->Color.BlendEnabled); // GL_BLEND
791 FALLBACK_IF(ctx->Polygon.OffsetFill); // GL_POLYGON_OFFSET_FILL
792 #endif
793 FALLBACK_IF(ctx->Polygon.OffsetPoint); // GL_POLYGON_OFFSET_POINT
794 FALLBACK_IF(ctx->Polygon.OffsetLine); // GL_POLYGON_OFFSET_LINE
795 //FALLBACK_IF(ctx->Stencil.Enabled); // GL_STENCIL_TEST
796
797 //FALLBACK_IF(ctx->Fog.Enabled); // GL_FOG disable as swtcl doesnt seem to support this
798 //FALLBACK_IF(ctx->Polygon.SmoothFlag); // GL_POLYGON_SMOOTH disabling to get blender going
799 FALLBACK_IF(ctx->Polygon.StippleFlag); // GL_POLYGON_STIPPLE
800 FALLBACK_IF(ctx->Multisample.Enabled); // GL_MULTISAMPLE_ARB
801
802
803 FALLBACK_IF(ctx->Line.StippleFlag);
804
805 /* HW doesnt appear to directly support these */
806 FALLBACK_IF(ctx->Line.SmoothFlag); // GL_LINE_SMOOTH
807 FALLBACK_IF(ctx->Point.SmoothFlag); // GL_POINT_SMOOTH
808 /* Rest could be done with vertex fragments */
809 if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite)
810 FALLBACK_IF(ctx->Point.PointSprite); // GL_POINT_SPRITE_NV
811
812 return GL_FALSE;
813 }
814
815 /**
816 * Called by the pipeline manager to render a batch of primitives.
817 * We can return true to pass on to the next stage (i.e. software
818 * rasterization) or false to indicate that the pipeline has finished
819 * after we render something.
820 */
821 static GLboolean r300_run_render(GLcontext *ctx,
822 struct tnl_pipeline_stage *stage)
823 {
824
825 if (RADEON_DEBUG & DEBUG_PRIMS)
826 fprintf(stderr, "%s\n", __FUNCTION__);
827
828 if (r300Fallback(ctx))
829 return GL_TRUE;
830 #if 0
831 return r300_run_immediate_render(ctx, stage);
832 #else
833 return r300_run_vb_render(ctx, stage);
834 #endif
835 }
836
837 const struct tnl_pipeline_stage _r300_render_stage = {
838 "r300 hw rasterize",
839 NULL,
840 NULL,
841 NULL,
842 NULL,
843 r300_run_render /* run */
844 };
845
846 static GLboolean r300_run_tcl_render(GLcontext *ctx,
847 struct tnl_pipeline_stage *stage)
848 {
849 r300ContextPtr rmesa = R300_CONTEXT(ctx);
850
851 hw_tcl_on=future_hw_tcl_on;
852
853 if (RADEON_DEBUG & DEBUG_PRIMS)
854 fprintf(stderr, "%s\n", __FUNCTION__);
855 if(hw_tcl_on == GL_FALSE)
856 return GL_TRUE;
857
858 //r300UpdateShaders(rmesa);
859 //r300UpdateShaderStates(rmesa);
860
861 return r300_run_vb_render(ctx, stage);
862 }
863
864 static void r300_check_tcl_render(GLcontext *ctx, struct tnl_pipeline_stage *stage)
865 {
866
867 if (RADEON_DEBUG & DEBUG_STATE)
868 fprintf(stderr, "%s\n", __FUNCTION__);
869
870 /* We only support rendering in hardware for now */
871 if (ctx->RenderMode != GL_RENDER) {
872 //stage->active = GL_FALSE;
873 return;
874 }
875 }
876
877 const struct tnl_pipeline_stage _r300_tcl_stage = {
878 "r300 tcl",
879 NULL,
880 NULL,
881 NULL,
882 NULL,
883 r300_run_tcl_render /* run */
884 };