r300 driver side of color tiling support.
[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
48 #include "radeon_reg.h"
49 #include "radeon_macros.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_state.h"
52 #include "r300_context.h"
53 #include "r300_ioctl.h"
54 #include "r300_state.h"
55 #include "r300_reg.h"
56 #include "r300_program.h"
57 #include "r300_tex.h"
58 #include "r300_maos.h"
59 #include "r300_emit.h"
60
61 extern int future_hw_tcl_on;
62
63 /**********************************************************************
64 * Hardware rasterization
65 *
66 * When we fell back to software TCL, we still try to use the
67 * rasterization hardware for rendering.
68 **********************************************************************/
69
70 static int r300_get_primitive_type(r300ContextPtr rmesa, GLcontext *ctx, int prim)
71 {
72 TNLcontext *tnl = TNL_CONTEXT(ctx);
73 struct vertex_buffer *VB = &tnl->vb;
74 GLuint i;
75 int type=-1;
76
77 switch (prim & PRIM_MODE_MASK) {
78 case GL_POINTS:
79 type=R300_VAP_VF_CNTL__PRIM_POINTS;
80 break;
81 case GL_LINES:
82 type=R300_VAP_VF_CNTL__PRIM_LINES;
83 break;
84 case GL_LINE_STRIP:
85 type=R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
86 break;
87 case GL_LINE_LOOP:
88 type=R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
89 break;
90 case GL_TRIANGLES:
91 type=R300_VAP_VF_CNTL__PRIM_TRIANGLES;
92 break;
93 case GL_TRIANGLE_STRIP:
94 type=R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP;
95 break;
96 case GL_TRIANGLE_FAN:
97 type=R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN;
98 break;
99 case GL_QUADS:
100 type=R300_VAP_VF_CNTL__PRIM_QUADS;
101 break;
102 case GL_QUAD_STRIP:
103 type=R300_VAP_VF_CNTL__PRIM_QUAD_STRIP;
104 break;
105 case GL_POLYGON:
106 type=R300_VAP_VF_CNTL__PRIM_POLYGON;
107 break;
108 default:
109 fprintf(stderr, "%s:%s Do not know how to handle primitive %02x - help me !\n",
110 __FILE__, __FUNCTION__,
111 prim & PRIM_MODE_MASK);
112 return -1;
113 break;
114 }
115 return type;
116 }
117
118 static int r300_get_num_verts(r300ContextPtr rmesa,
119 GLcontext *ctx,
120 int num_verts,
121 int prim)
122 {
123 TNLcontext *tnl = TNL_CONTEXT(ctx);
124 struct vertex_buffer *VB = &tnl->vb;
125 GLuint i;
126 int type=-1, verts_off=0;
127 char *name="UNKNOWN";
128
129 switch (prim & PRIM_MODE_MASK) {
130 case GL_POINTS:
131 name="P";
132 verts_off = 0;
133 break;
134 case GL_LINES:
135 name="L";
136 verts_off = num_verts % 2;
137 break;
138 case GL_LINE_STRIP:
139 name="LS";
140 if(num_verts < 2)
141 verts_off = num_verts;
142 break;
143 case GL_LINE_LOOP:
144 name="LL";
145 if(num_verts < 2)
146 verts_off = num_verts;
147 break;
148 case GL_TRIANGLES:
149 name="T";
150 verts_off = num_verts % 3;
151 break;
152 case GL_TRIANGLE_STRIP:
153 name="TS";
154 if(num_verts < 3)
155 verts_off = num_verts;
156 break;
157 case GL_TRIANGLE_FAN:
158 name="TF";
159 if(num_verts < 3)
160 verts_off = num_verts;
161 break;
162 case GL_QUADS:
163 name="Q";
164 verts_off = num_verts % 4;
165 break;
166 case GL_QUAD_STRIP:
167 name="QS";
168 if(num_verts < 4)
169 verts_off = num_verts;
170 else
171 verts_off = num_verts % 2;
172 break;
173 case GL_POLYGON:
174 name="P";
175 if(num_verts < 3)
176 verts_off = num_verts;
177 break;
178 default:
179 fprintf(stderr, "%s:%s Do not know how to handle primitive %02x - help me !\n",
180 __FILE__, __FUNCTION__,
181 prim & PRIM_MODE_MASK);
182 return -1;
183 break;
184 }
185
186 if(num_verts - verts_off == 0){
187 WARN_ONCE("user error: Need more than %d vertices to draw primitive %s !\n", num_verts, name);
188 return 0;
189 }
190
191 if(verts_off > 0){
192 WARN_ONCE("user error: %d is not a valid number of vertices for primitive %s !\n", num_verts, name);
193 }
194
195 return num_verts - verts_off;
196 }
197
198 /* This function compiles GL context into state registers that
199 describe data routing inside of R300 pipeline.
200
201 In particular, it programs input_route, output_vtx_fmt, texture
202 unit configuration and gb_output_vtx_fmt
203
204 This function encompasses setup_AOS() from r300_lib.c
205 */
206
207
208
209
210 /* Immediate implementation - vertex data is sent via command stream */
211
212 static GLfloat default_vector[4]={0.0, 0.0, 0.0, 1.0};
213
214 #define output_vector(v, i) { \
215 int _i; \
216 for(_i=0;_i<v->size;_i++){ \
217 if(VB->Elts){ \
218 efloat(VEC_ELT(v, GLfloat, VB->Elts[i])[_i]); \
219 }else{ \
220 efloat(VEC_ELT(v, GLfloat, i)[_i]); \
221 } \
222 } \
223 for(_i=v->size;_i<4;_i++){ \
224 efloat(default_vector[_i]); \
225 } \
226 }
227
228 /* Immediate implementation - vertex data is sent via command stream */
229
230 static void r300_render_immediate_primitive(r300ContextPtr rmesa,
231 GLcontext *ctx,
232 int start,
233 int end,
234 int prim)
235 {
236 TNLcontext *tnl = TNL_CONTEXT(ctx);
237 struct vertex_buffer *VB = &tnl->vb;
238 GLuint i, render_inputs;
239 int k, type, num_verts;
240 LOCAL_VARS
241
242 type=r300_get_primitive_type(rmesa, ctx, prim);
243 num_verts=r300_get_num_verts(rmesa, ctx, end-start, prim);
244
245 #if 0
246 fprintf(stderr,"ObjPtr: size=%d stride=%d\n",
247 VB->ObjPtr->size, VB->ObjPtr->stride);
248 fprintf(stderr,"ColorPtr[0]: size=%d stride=%d\n",
249 VB->ColorPtr[0]->size, VB->ColorPtr[0]->stride);
250 fprintf(stderr,"TexCoordPtr[0]: size=%d stride=%d\n",
251 VB->TexCoordPtr[0]->size, VB->TexCoordPtr[0]->stride);
252 #endif
253
254 if(type<0 || num_verts <= 0)return;
255
256 if(!VB->ObjPtr){
257 WARN_ONCE("FIXME: Don't know how to handle GL_ARB_vertex_buffer_object correctly\n");
258 return;
259 }
260 /* A packet cannot have more than 16383 data words.. */
261 if((num_verts*4*rmesa->state.aos_count)>16380){
262 WARN_ONCE("Too many vertices to paint. Fix me !\n");
263 return;
264 }
265
266 //fprintf(stderr, "aos_count=%d start=%d end=%d\n", rmesa->state.aos_count, start, end);
267
268 if(rmesa->state.aos_count==0){
269 WARN_ONCE("Aeiee ! aos_count==0, while it shouldn't. Skipping rendering\n");
270 return;
271 }
272
273 render_inputs = rmesa->state.render_inputs;
274
275 if(!render_inputs){
276 WARN_ONCE("Aeiee ! render_inputs==0. Skipping rendering.\n");
277 return;
278 }
279
280
281 start_immediate_packet(num_verts, type, 4*rmesa->state.aos_count);
282
283 for(i=start;i<start+num_verts;i++){
284 #if 0
285 fprintf(stderr, "* (%f %f %f %f) (%f %f %f %f)\n",
286 VEC_ELT(VB->ObjPtr, GLfloat, i)[0],
287 VEC_ELT(VB->ObjPtr, GLfloat, i)[1],
288 VEC_ELT(VB->ObjPtr, GLfloat, i)[2],
289 VEC_ELT(VB->ObjPtr, GLfloat, i)[3],
290
291 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[0],
292 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[1],
293 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[2],
294 VEC_ELT(VB->ColorPtr[0], GLfloat, i)[3]
295 );
296 #endif
297
298
299 /* coordinates */
300 if(render_inputs & _TNL_BIT_POS)
301 output_vector(VB->ObjPtr, i);
302 if(render_inputs & _TNL_BIT_NORMAL)
303 output_vector(VB->NormalPtr, i);
304
305 /* color components */
306 if(render_inputs & _TNL_BIT_COLOR0)
307 output_vector(VB->ColorPtr[0], i);
308 if(render_inputs & _TNL_BIT_COLOR1)
309 output_vector(VB->SecondaryColorPtr[0], i);
310
311 /* if(render_inputs & _TNL_BIT_FOG) // Causes lock ups when immediate mode is on
312 output_vector(VB->FogCoordPtr, i);*/
313
314 /* texture coordinates */
315 for(k=0;k < ctx->Const.MaxTextureUnits;k++)
316 if(render_inputs & (_TNL_BIT_TEX0<<k))
317 output_vector(VB->TexCoordPtr[k], i);
318
319 if(render_inputs & _TNL_BIT_INDEX)
320 output_vector(VB->IndexPtr[0], i);
321 if(render_inputs & _TNL_BIT_POINTSIZE)
322 output_vector(VB->PointSizePtr, i);
323 }
324
325 }
326
327
328 static GLboolean r300_run_immediate_render(GLcontext *ctx,
329 struct tnl_pipeline_stage *stage)
330 {
331 r300ContextPtr rmesa = R300_CONTEXT(ctx);
332 TNLcontext *tnl = TNL_CONTEXT(ctx);
333 struct vertex_buffer *VB = &tnl->vb;
334 GLuint i;
335 /* Only do 2d textures */
336 struct gl_texture_object *to=ctx->Texture.Unit[0].Current2D;
337 r300TexObjPtr t=to->DriverData;
338 LOCAL_VARS
339
340
341 /* Update texture state - needs to be done only when actually changed..
342 All the time for now.. */
343
344
345 if (RADEON_DEBUG == DEBUG_PRIMS)
346 fprintf(stderr, "%s\n", __FUNCTION__);
347
348 #if 1 /* we need this, somehow */
349 /* Flush state - make sure command buffer is nice and large */
350 r300Flush(ctx);
351 /* Make sure we have enough space */
352 #else
353 /* Count is very imprecize, but should be good upper bound */
354 r300EnsureCmdBufSpace(rmesa, rmesa->hw.max_state_size + 4+2+30
355 +VB->PrimitiveCount*(1+8)+VB->Count*4*rmesa->state.texture.tc_count+4, __FUNCTION__);
356 #endif
357
358 /* needed before starting 3d operation .. */
359 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
360 e32(0x0000000a);
361
362 reg_start(0x4f18,0);
363 e32(0x00000003);
364
365
366 #if 0 /* looks like the Z offset issue got fixed */
367 rmesa->hw.vte.cmd[1] = R300_VPORT_X_SCALE_ENA
368 | R300_VPORT_X_OFFSET_ENA
369 | R300_VPORT_Y_SCALE_ENA
370 | R300_VPORT_Y_OFFSET_ENA
371 | R300_VTX_W0_FMT;
372 R300_STATECHANGE(rmesa, vte);
373 #endif
374
375
376
377 /* Magic register - note it is right after 20b0 */
378
379
380 if(rmesa->state.texture.tc_count>0){
381 reg_start(0x20b4,0);
382 e32(0x0000000c);
383
384 }
385
386 r300EmitState(rmesa);
387
388 /* Setup INPUT_ROUTE and INPUT_CNTL */
389 r300EmitArrays(ctx, GL_TRUE);
390
391 /* Why do we need this for immediate mode?? Vertex processor needs it to know proper regs */
392 // r300EmitLOAD_VBPNTR(rmesa, 0);
393 /* Okay, it seems I misunderstood something, EmitAOS does the same thing */
394 r300EmitAOS(rmesa, rmesa->state.aos_count, 0);
395
396 for(i=0; i < VB->PrimitiveCount; i++){
397 GLuint prim = VB->Primitive[i].mode;
398 GLuint start = VB->Primitive[i].start;
399 GLuint length = VB->Primitive[i].count;
400
401 r300_render_immediate_primitive(rmesa, ctx, start, start + length, prim);
402 }
403
404 /* This sequence is required after any 3d drawing packet
405 I suspect it work arounds a bug (or deficiency) in hardware */
406
407 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
408 e32(0x0000000a);
409
410 reg_start(0x4f18,0);
411 e32(0x00000003);
412
413 return GL_FALSE;
414 }
415
416
417 /* vertex buffer implementation */
418
419 static void inline fire_EB(PREFIX unsigned long addr, int vertex_count, int type)
420 {
421 LOCAL_VARS
422 unsigned long addr_a;
423
424 if(addr & 1){
425 WARN_ONCE("Badly aligned buffer\n");
426 return ;
427 }
428 addr_a = 0; /*addr & 0x1c;*/
429
430 check_space(6);
431
432 start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, 0);
433 /* TODO: R300_VAP_VF_CNTL__INDEX_SIZE_32bit . */
434 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count<<16) | type);
435
436 start_packet3(RADEON_CP_PACKET3_INDX_BUFFER, 2);
437 e32(R300_EB_UNK1 | (addr_a << 16) | R300_EB_UNK2);
438 e32(addr /*& 0xffffffe3*/);
439 e32((vertex_count+1)/2 /*+ addr_a/4*/); /* Total number of dwords needed? */
440 }
441
442 static void r300_render_vb_primitive(r300ContextPtr rmesa,
443 GLcontext *ctx,
444 int start,
445 int end,
446 int prim)
447 {
448 int type, num_verts;
449 radeonScreenPtr rsp=rmesa->radeon.radeonScreen;
450 LOCAL_VARS
451 TNLcontext *tnl = TNL_CONTEXT(ctx);
452 struct vertex_buffer *VB = &tnl->vb;
453 int i;
454
455 type=r300_get_primitive_type(rmesa, ctx, prim);
456 num_verts=r300_get_num_verts(rmesa, ctx, end-start, prim);
457
458 if(type<0 || num_verts <= 0)return;
459
460 if(rmesa->state.Elts){
461 r300EmitAOS(rmesa, rmesa->state.aos_count, 0);
462 #if 0
463 start_index32_packet(num_verts, type);
464 for(i=0; i < num_verts; i++)
465 e32(rmesa->state.Elts[start+i]); /* start ? */
466 #else
467 WARN_ONCE("Rendering with elt buffers\n");
468 if(num_verts == 1){
469 start_index32_packet(num_verts, type);
470 e32(rmesa->state.Elts[start]);
471 return;
472 }
473
474 if(num_verts > 65535){ /* not implemented yet */
475 WARN_ONCE("Too many elts\n");
476 return;
477 }
478 r300EmitElts(ctx, rmesa->state.Elts+start, num_verts);
479 fire_EB(PASS_PREFIX GET_START(&(rmesa->state.elt_dma)), num_verts, type);
480 #endif
481 }else{
482 r300EmitAOS(rmesa, rmesa->state.aos_count, start);
483 fire_AOS(PASS_PREFIX num_verts, type);
484 }
485 }
486
487 static GLboolean r300_run_vb_render(GLcontext *ctx,
488 struct tnl_pipeline_stage *stage)
489 {
490 r300ContextPtr rmesa = R300_CONTEXT(ctx);
491 TNLcontext *tnl = TNL_CONTEXT(ctx);
492 struct vertex_buffer *VB = &tnl->vb;
493 int i, j;
494 LOCAL_VARS
495
496 if (RADEON_DEBUG & DEBUG_PRIMS)
497 fprintf(stderr, "%s\n", __FUNCTION__);
498
499
500 r300ReleaseArrays(ctx);
501 r300EmitArrays(ctx, GL_FALSE);
502
503 // LOCK_HARDWARE(&(rmesa->radeon));
504
505 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
506 e32(0x0000000a);
507
508 reg_start(0x4f18,0);
509 e32(0x00000003);
510 r300EmitState(rmesa);
511
512 rmesa->state.Elts = VB->Elts;
513
514 for(i=0; i < VB->PrimitiveCount; i++){
515 GLuint prim = VB->Primitive[i].mode;
516 GLuint start = VB->Primitive[i].start;
517 GLuint length = VB->Primitive[i].count;
518
519 r300_render_vb_primitive(rmesa, ctx, start, start + length, prim);
520 }
521
522 reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
523 e32(0x0000000a);
524
525 reg_start(0x4f18,0);
526 e32(0x00000003);
527
528 // end_3d(PASS_PREFIX_VOID);
529
530 /* Flush state - we are done drawing.. */
531 // r300FlushCmdBufLocked(rmesa, __FUNCTION__);
532 // radeonWaitForIdleLocked(&(rmesa->radeon));
533
534 // UNLOCK_HARDWARE(&(rmesa->radeon));
535 return GL_FALSE;
536 }
537
538 /**
539 * Called by the pipeline manager to render a batch of primitives.
540 * We can return true to pass on to the next stage (i.e. software
541 * rasterization) or false to indicate that the pipeline has finished
542 * after we render something.
543 */
544 static GLboolean r300_run_render(GLcontext *ctx,
545 struct tnl_pipeline_stage *stage)
546 {
547 r300ContextPtr rmesa = R300_CONTEXT(ctx);
548 TNLcontext *tnl = TNL_CONTEXT(ctx);
549 struct vertex_buffer *VB = &tnl->vb;
550 GLuint i;
551
552 if (RADEON_DEBUG & DEBUG_PRIMS)
553 fprintf(stderr, "%s\n", __FUNCTION__);
554
555
556 #if 1
557
558 #if 0
559 return r300_run_immediate_render(ctx, stage);
560 #else
561 return r300_run_vb_render(ctx, stage);
562 #endif
563 #else
564 return GL_TRUE;
565 #endif
566 }
567
568
569 /**
570 * Called by the pipeline manager once before rendering.
571 * We check the GL state here to
572 * a) decide whether we can do the current state in hardware and
573 * b) update hardware registers
574 */
575 #define FALLBACK_IF(expr) \
576 do { \
577 if (expr) { \
578 if (1 || RADEON_DEBUG & DEBUG_FALLBACKS) \
579 fprintf(stderr, "%s: fallback:%s\n", \
580 __FUNCTION__, #expr); \
581 /*stage->active = GL_FALSE*/; \
582 return; \
583 } \
584 } while(0)
585
586 static void r300_check_render(GLcontext *ctx, struct tnl_pipeline_stage *stage)
587 {
588 r300ContextPtr r300 = R300_CONTEXT(ctx);
589 int i;
590
591 if (RADEON_DEBUG & DEBUG_STATE)
592 fprintf(stderr, "%s\n", __FUNCTION__);
593
594 /* We only support rendering in hardware for now */
595 if (ctx->RenderMode != GL_RENDER) {
596 //stage->active = GL_FALSE;
597 return;
598 }
599
600
601 /* I'm almost certain I forgot something here */
602 #if 0 /* These should work now.. */
603 FALLBACK_IF(ctx->Color.DitherFlag);
604 FALLBACK_IF(ctx->Color.AlphaEnabled); // GL_ALPHA_TEST
605 FALLBACK_IF(ctx->Color.BlendEnabled); // GL_BLEND
606 FALLBACK_IF(ctx->Polygon.OffsetFill); // GL_POLYGON_OFFSET_FILL
607 #endif
608 //FALLBACK_IF(ctx->Polygon.OffsetPoint); // GL_POLYGON_OFFSET_POINT
609 //FALLBACK_IF(ctx->Polygon.OffsetLine); // GL_POLYGON_OFFSET_LINE
610 //FALLBACK_IF(ctx->Stencil.Enabled); // GL_STENCIL_TEST
611
612 //FALLBACK_IF(ctx->Fog.Enabled); // GL_FOG disable as swtcl doesnt seem to support this
613 //FALLBACK_IF(ctx->Polygon.SmoothFlag); // GL_POLYGON_SMOOTH disabling to get blender going
614 FALLBACK_IF(ctx->Polygon.StippleFlag); // GL_POLYGON_STIPPLE
615 FALLBACK_IF(ctx->Multisample.Enabled); // GL_MULTISAMPLE_ARB
616
617 #if 0 /* ut2k3 fails to start if this is on */
618 /* One step at a time - let one texture pass.. */
619 for (i = 1; i < ctx->Const.MaxTextureUnits; i++)
620 FALLBACK_IF(ctx->Texture.Unit[i].Enabled);
621 #endif
622
623 /* Assumed factor reg is found but pattern is still missing */
624 //FALLBACK_IF(ctx->Line.StippleFlag); // GL_LINE_STIPPLE disabling to get blender going
625
626 /* HW doesnt appear to directly support these */
627 //FALLBACK_IF(ctx->Line.SmoothFlag); // GL_LINE_SMOOTH disabling to get blender going
628 FALLBACK_IF(ctx->Point.SmoothFlag); // GL_POINT_SMOOTH
629 /* Rest could be done with vertex fragments */
630 if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite)
631 FALLBACK_IF(ctx->Point.PointSprite); // GL_POINT_SPRITE_NV
632 //GL_POINT_DISTANCE_ATTENUATION_ARB
633 //GL_POINT_FADE_THRESHOLD_SIZE_ARB
634
635 /* let r300_run_render do its job */
636 #if 0
637 stage->active = GL_FALSE;
638 #endif
639 }
640
641
642 static void dtr(struct tnl_pipeline_stage *stage)
643 {
644 (void)stage;
645 }
646
647 GLboolean r300_create_render(GLcontext *ctx, struct tnl_pipeline_stage *stage){
648 return GL_TRUE;
649 }
650
651
652 const struct tnl_pipeline_stage _r300_render_stage = {
653 "r300 hw rasterize",
654 NULL,
655 r300_create_render,
656 dtr, /* destructor */
657 r300_check_render, /* check */
658 r300_run_render /* run */
659 };
660
661 static GLboolean r300_run_tcl_render(GLcontext *ctx,
662 struct tnl_pipeline_stage *stage)
663 {
664 r300ContextPtr rmesa = R300_CONTEXT(ctx);
665 TNLcontext *tnl = TNL_CONTEXT(ctx);
666 struct vertex_buffer *VB = &tnl->vb;
667 GLuint i;
668 struct r300_vertex_program *vp;
669
670 hw_tcl_on=future_hw_tcl_on;
671
672 if (RADEON_DEBUG & DEBUG_PRIMS)
673 fprintf(stderr, "%s\n", __FUNCTION__);
674 if(hw_tcl_on == GL_FALSE)
675 return GL_TRUE;
676 if(ctx->VertexProgram._Enabled == GL_FALSE){
677 _tnl_UpdateFixedFunctionProgram(ctx);
678 }
679 vp = CURRENT_VERTEX_SHADER(ctx);
680 if(vp->translated == GL_FALSE)
681 translate_vertex_shader(vp);
682 if(vp->translated == GL_FALSE){
683 fprintf(stderr, "Failing back to sw-tcl\n");
684 debug_vp(ctx, vp);
685 hw_tcl_on=future_hw_tcl_on=0;
686 r300ResetHwState(rmesa);
687 return GL_TRUE;
688 }
689
690 r300_setup_textures(ctx);
691 r300_setup_rs_unit(ctx);
692
693 r300SetupVertexShader(rmesa);
694 r300SetupPixelShader(rmesa);
695
696 return r300_run_vb_render(ctx, stage);
697 }
698
699 static void r300_check_tcl_render(GLcontext *ctx, struct tnl_pipeline_stage *stage)
700 {
701 r300ContextPtr r300 = R300_CONTEXT(ctx);
702 int i;
703
704 if (RADEON_DEBUG & DEBUG_STATE)
705 fprintf(stderr, "%s\n", __FUNCTION__);
706
707 /* We only support rendering in hardware for now */
708 if (ctx->RenderMode != GL_RENDER) {
709 //stage->active = GL_FALSE;
710 return;
711 }
712 }
713
714 const struct tnl_pipeline_stage _r300_tcl_stage = {
715 "r300 tcl",
716 NULL,
717 r300_create_render,
718 dtr, /* destructor */
719 r300_check_tcl_render, /* check */
720 r300_run_tcl_render /* run */
721 };