1 /**************************************************************************
3 Copyright (C) 2004 Nicolai Haehnle.
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:
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
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.
26 **************************************************************************/
30 * Nicolai Haehnle <prefect_@gmx.net>
40 #include "simple_list.h"
42 #include "api_arrayelt.h"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
45 #include "array_cache/acache.h"
47 #include "tnl/t_vp_build.h"
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"
57 #include "r300_program.h"
59 #include "r300_maos.h"
60 #include "r300_emit.h"
62 extern int future_hw_tcl_on
;
64 /**********************************************************************
65 * Hardware rasterization
67 * When we fell back to software TCL, we still try to use the
68 * rasterization hardware for rendering.
69 **********************************************************************/
71 static int r300_get_primitive_type(r300ContextPtr rmesa
, GLcontext
*ctx
, int prim
)
75 switch (prim
& PRIM_MODE_MASK
) {
77 type
=R300_VAP_VF_CNTL__PRIM_POINTS
;
80 type
=R300_VAP_VF_CNTL__PRIM_LINES
;
83 type
=R300_VAP_VF_CNTL__PRIM_LINE_STRIP
;
86 type
=R300_VAP_VF_CNTL__PRIM_LINE_LOOP
;
89 type
=R300_VAP_VF_CNTL__PRIM_TRIANGLES
;
91 case GL_TRIANGLE_STRIP
:
92 type
=R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP
;
95 type
=R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN
;
98 type
=R300_VAP_VF_CNTL__PRIM_QUADS
;
101 type
=R300_VAP_VF_CNTL__PRIM_QUAD_STRIP
;
104 type
=R300_VAP_VF_CNTL__PRIM_POLYGON
;
107 fprintf(stderr
, "%s:%s Do not know how to handle primitive %02x - help me !\n",
108 __FILE__
, __FUNCTION__
,
109 prim
& PRIM_MODE_MASK
);
116 static int r300_get_num_verts(r300ContextPtr rmesa
,
122 char *name
="UNKNOWN";
124 switch (prim
& PRIM_MODE_MASK
) {
131 verts_off
= num_verts
% 2;
136 verts_off
= num_verts
;
141 verts_off
= num_verts
;
145 verts_off
= num_verts
% 3;
147 case GL_TRIANGLE_STRIP
:
150 verts_off
= num_verts
;
152 case GL_TRIANGLE_FAN
:
155 verts_off
= num_verts
;
159 verts_off
= num_verts
% 4;
164 verts_off
= num_verts
;
166 verts_off
= num_verts
% 2;
171 verts_off
= num_verts
;
174 fprintf(stderr
, "%s:%s Do not know how to handle primitive %02x - help me !\n",
175 __FILE__
, __FUNCTION__
,
176 prim
& PRIM_MODE_MASK
);
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
);
188 WARN_ONCE("user error: %d is not a valid number of vertices for primitive %s !\n", num_verts
, name
);
192 return num_verts
- verts_off
;
195 /* This function compiles GL context into state registers that
196 describe data routing inside of R300 pipeline.
198 In particular, it programs input_route, output_vtx_fmt, texture
199 unit configuration and gb_output_vtx_fmt
201 This function encompasses setup_AOS() from r300_lib.c
207 /* Immediate implementation - vertex data is sent via command stream */
209 static GLfloat default_vector
[4]={0.0, 0.0, 0.0, 1.0};
211 #define output_vector(v, i) { \
213 for(_i=0;_i<v->size;_i++){ \
215 efloat(VEC_ELT(v, GLfloat, VB->Elts[i])[_i]); \
217 efloat(VEC_ELT(v, GLfloat, i)[_i]); \
220 for(_i=v->size;_i<4;_i++){ \
221 efloat(default_vector[_i]); \
225 /* Immediate implementation - vertex data is sent via command stream */
227 static void r300_render_immediate_primitive(r300ContextPtr rmesa
,
233 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
234 struct vertex_buffer
*VB
= &tnl
->vb
;
235 GLuint i
, render_inputs
;
236 int k
, type
, num_verts
;
239 type
=r300_get_primitive_type(rmesa
, ctx
, prim
);
240 num_verts
=r300_get_num_verts(rmesa
, ctx
, end
-start
, prim
);
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
);
251 if(type
<0 || num_verts
<= 0)return;
254 WARN_ONCE("FIXME: Don't know how to handle GL_ARB_vertex_buffer_object correctly\n");
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");
263 //fprintf(stderr, "aos_count=%d start=%d end=%d\n", rmesa->state.aos_count, start, end);
265 if(rmesa
->state
.aos_count
==0){
266 WARN_ONCE("Aeiee ! aos_count==0, while it shouldn't. Skipping rendering\n");
270 render_inputs
= rmesa
->state
.render_inputs
;
273 WARN_ONCE("Aeiee ! render_inputs==0. Skipping rendering.\n");
278 start_immediate_packet(num_verts
, type
, 4*rmesa
->state
.aos_count
);
280 for(i
=start
;i
<start
+num_verts
;i
++){
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],
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]
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
);
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
);
308 /* if(render_inputs & _TNL_BIT_FOG) // Causes lock ups when immediate mode is on
309 output_vector(VB->FogCoordPtr, i);*/
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
);
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
);
325 static GLboolean
r300_run_immediate_render(GLcontext
*ctx
,
326 struct tnl_pipeline_stage
*stage
)
328 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
329 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
330 struct vertex_buffer
*VB
= &tnl
->vb
;
335 /* Update texture state - needs to be done only when actually changed..
336 All the time for now.. */
339 if (RADEON_DEBUG
== DEBUG_PRIMS
)
340 fprintf(stderr
, "%s\n", __FUNCTION__
);
342 #if 1 /* we need this, somehow */
343 /* Flush state - make sure command buffer is nice and large */
345 /* Make sure we have enough space */
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__
);
352 /* needed before starting 3d operation .. */
353 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
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
366 R300_STATECHANGE(rmesa
, vte
);
371 /* Magic register - note it is right after 20b0 */
374 if(rmesa
->state
.texture
.tc_count
>0){
380 r300EmitState(rmesa
);
382 /* Setup INPUT_ROUTE and INPUT_CNTL */
383 r300EmitArrays(ctx
, GL_TRUE
);
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);
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
;
395 r300_render_immediate_primitive(rmesa
, ctx
, start
, start
+ length
, prim
);
398 /* This sequence is required after any 3d drawing packet
399 I suspect it work arounds a bug (or deficiency) in hardware */
401 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
411 /* vertex buffer implementation */
413 static void inline fire_EB(PREFIX
unsigned long addr
, int vertex_count
, int type
, int elt_size
)
416 unsigned long addr_a
;
417 unsigned long t_addr
;
418 unsigned long magic_1
, magic_2
;
420 ctx
= rmesa
->radeon
.glCtx
;
422 assert(elt_size
== 2 || elt_size
== 4);
424 if(addr
& (elt_size
-1)){
425 WARN_ONCE("Badly aligned buffer\n");
431 magic_1
= (addr
% 32) / 4;
432 t_addr
= addr
& (~0x1d);
433 magic_2
= (vertex_count
+ 1 + (t_addr
& 0x2)) / 2 + magic_1
;
437 start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2
, 0);
439 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (vertex_count
<<16) | type
| R300_VAP_VF_CNTL__INDEX_SIZE_32bit
);
441 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (vertex_count
<<16) | type
);
444 start_packet3(RADEON_CP_PACKET3_INDX_BUFFER
, 2);
446 e32(R300_EB_UNK1
| (0 << 16) | R300_EB_UNK2
);
447 e32(addr
/*& 0xffffffe3*/);
449 e32(R300_EB_UNK1
| (magic_1
<< 16) | R300_EB_UNK2
);
454 e32(vertex_count
/*+ addr_a/4*/); /* Total number of dwords needed? */
456 e32(magic_2
); /* Total number of dwords needed? */
458 //cp_delay(PASS_PREFIX 1);
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
);
466 (void)magic_2
, (void)magic_1
, (void)t_addr
;
472 start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2
, 0);
474 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (vertex_count
<<16) | type
| R300_VAP_VF_CNTL__INDEX_SIZE_32bit
);
476 e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (vertex_count
<<16) | type
);
479 start_packet3(RADEON_CP_PACKET3_INDX_BUFFER
, 2);
480 e32(R300_EB_UNK1
| (0 << 16) | R300_EB_UNK2
);
481 e32(addr
/*& 0xffffffe3*/);
484 e32(vertex_count
/*+ addr_a/4*/); /* Total number of dwords needed? */
486 e32((vertex_count
+1)/2 /*+ addr_a/4*/); /* Total number of dwords needed? */
488 //cp_delay(PASS_PREFIX 1);
492 static void r300_render_vb_primitive(r300ContextPtr rmesa
,
501 type
=r300_get_primitive_type(rmesa
, ctx
, prim
);
502 num_verts
=r300_get_num_verts(rmesa
, ctx
, end
-start
, prim
);
504 if(type
<0 || num_verts
<= 0)return;
506 if(rmesa
->state
.Elts
){
507 r300EmitAOS(rmesa
, rmesa
->state
.aos_count
, 0);
510 start_index32_packet(num_verts
, type
);
511 for(i
=0; i
< num_verts
; i
++)
512 e32(rmesa
->state
.Elts
[start
+i
]); /* start ? */
515 start_index32_packet(num_verts
, type
);
516 e32(rmesa
->state
.Elts
[start
]);
520 if(num_verts
> 65535){ /* not implemented yet */
521 WARN_ONCE("Too many elts\n");
524 r300EmitElts(ctx
, rmesa
->state
.Elts
+start
, num_verts
, 4);
525 fire_EB(PASS_PREFIX
GET_START(&(rmesa
->state
.elt_dma
)), num_verts
, type
, 4);
528 r300EmitAOS(rmesa
, rmesa
->state
.aos_count
, start
);
529 fire_AOS(PASS_PREFIX num_verts
, type
);
533 static GLboolean
r300_run_vb_render(GLcontext
*ctx
,
534 struct tnl_pipeline_stage
*stage
)
536 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
537 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
538 struct vertex_buffer
*VB
= &tnl
->vb
;
542 if (RADEON_DEBUG
& DEBUG_PRIMS
)
543 fprintf(stderr
, "%s\n", __FUNCTION__
);
546 //r300UpdateShaders(rmesa);
548 r300ReleaseArrays(ctx
);
549 r300EmitArrays(ctx
, GL_FALSE
);
551 r300UpdateShaderStates(rmesa
);
552 // LOCK_HARDWARE(&(rmesa->radeon));
554 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
559 r300EmitState(rmesa
);
561 rmesa
->state
.Elts
= VB
->Elts
;
563 for(i
=0; i
< VB
->PrimitiveCount
; i
++){
564 GLuint prim
= VB
->Primitive
[i
].mode
;
565 GLuint start
= VB
->Primitive
[i
].start
;
566 GLuint length
= VB
->Primitive
[i
].count
;
568 r300_render_vb_primitive(rmesa
, ctx
, start
, start
+ length
, prim
);
571 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
580 // end_3d(PASS_PREFIX_VOID);
582 /* Flush state - we are done drawing.. */
583 // r300FlushCmdBufLocked(rmesa, __FUNCTION__);
584 // radeonWaitForIdleLocked(&(rmesa->radeon));
586 // UNLOCK_HARDWARE(&(rmesa->radeon));
590 #ifdef RADEON_VTXFMT_A
592 static void r300_render_vb_primitive_vtxfmt_a(r300ContextPtr rmesa
,
599 radeonScreenPtr rsp
=rmesa
->radeon
.radeonScreen
;
601 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
602 struct vertex_buffer
*VB
= &tnl
->vb
;
605 type
=r300_get_primitive_type(rmesa
, ctx
, prim
);
606 num_verts
=r300_get_num_verts(rmesa
, ctx
, end
-start
, prim
);
608 if(type
<0 || num_verts
<= 0)return;
610 if(rmesa
->state
.VB
.Elts
){
611 r300EmitAOS(rmesa
, rmesa
->state
.aos_count
, /*0*/start
);
613 start_index32_packet(num_verts
, type
);
614 for(i
=0; i
< num_verts
; i
++)
615 e32(((unsigned long *)rmesa
->state
.VB
.Elts
)[i
]/*rmesa->state.Elts[start+i]*/); /* start ? */
618 //start_index32_packet(num_verts, type);
619 //e32(rmesa->state.Elts[start]);
623 if(num_verts
> 65535){ /* not implemented yet */
624 WARN_ONCE("Too many elts\n");
628 r300EmitElts(ctx
, rmesa
->state
.VB
.Elts
, num_verts
, rmesa
->state
.VB
.elt_size
);
629 fire_EB(PASS_PREFIX rmesa
->state
.elt_dma
.aos_offset
, num_verts
, type
, rmesa
->state
.VB
.elt_size
);
632 r300EmitAOS(rmesa
, rmesa
->state
.aos_count
, start
);
633 fire_AOS(PASS_PREFIX num_verts
, type
);
637 void dump_array(struct r300_dma_region
*rvb
, int count
)
639 int *out
= (int *)(rvb
->address
+ rvb
->start
);
642 for (i
=0; i
< count
; i
++) {
643 fprintf(stderr
, "{");
644 if (rvb
->aos_format
== AOS_FORMAT_FLOAT
)
645 for (ci
=0; ci
< rvb
->aos_size
; ci
++)
646 fprintf(stderr
, "%f ", ((float *)out
)[ci
]);
648 for (ci
=0; ci
< rvb
->aos_size
; ci
++)
649 fprintf(stderr
, "%d ", ((unsigned char *)out
)[ci
]);
650 fprintf(stderr
, "}");
652 out
+= rvb
->aos_stride
;
655 fprintf(stderr
, "\n");
658 void dump_dt(struct dt
*dt
, int count
)
663 fprintf(stderr
, "base at %p ", out
);
665 for (i
=0; i
< count
; i
++){
666 fprintf(stderr
, "{");
667 if (dt
->type
== GL_FLOAT
)
668 for (ci
=0; ci
< dt
->size
; ci
++)
669 fprintf(stderr
, "%f ", ((float *)out
)[ci
]);
671 for (ci
=0; ci
< dt
->size
; ci
++)
672 fprintf(stderr
, "%d ", ((unsigned char *)out
)[ci
]);
673 fprintf(stderr
, "}");
675 out
= (char *)out
+ dt
->stride
;
678 fprintf(stderr
, "\n");
681 /*static */GLboolean
r300_run_vb_render_vtxfmt_a(GLcontext
*ctx
,
682 struct tnl_pipeline_stage
*stage
)
684 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
685 //TNLcontext *tnl = TNL_CONTEXT(ctx);
686 struct radeon_vertex_buffer
*VB
= &rmesa
->state
.VB
; //&tnl->vb;
690 if (RADEON_DEBUG
& DEBUG_PRIMS
)
691 fprintf(stderr
, "%s\n", __FUNCTION__
);
693 r300UpdateShaders(rmesa
);
694 if (rmesa
->state
.VB
.LockCount
== 0) {
695 r300ReleaseArrays(ctx
);
696 r300EmitArraysVtx(ctx
, GL_FALSE
);
698 r300UpdateShaderStates(rmesa
);
700 /* TODO: Figure out why do we need these. */
701 R300_STATECHANGE(rmesa
, vir
[0]);
702 R300_STATECHANGE(rmesa
, vir
[1]);
703 R300_STATECHANGE(rmesa
, vic
);
704 R300_STATECHANGE(rmesa
, vof
);
707 fprintf(stderr
, "dt:\n");
708 for(i
=0; i
< VERT_ATTRIB_MAX
; i
++){
709 fprintf(stderr
, "dt %d:", i
);
710 dump_dt(&rmesa
->state
.VB
.AttribPtr
[i
], VB
->Count
);
713 fprintf(stderr
, "before:\n");
714 for(i
=0; i
< rmesa
->state
.aos_count
; i
++){
715 fprintf(stderr
, "aos %d:", i
);
716 dump_array(&rmesa
->state
.aos
[i
], VB
->Count
);
720 r300ReleaseArrays(ctx
);
721 r300EmitArraysVtx(ctx
, GL_FALSE
);
723 fprintf(stderr
, "after:\n");
724 for(i
=0; i
< rmesa
->state
.aos_count
; i
++){
725 fprintf(stderr
, "aos %d:", i
);
726 dump_array(&rmesa
->state
.aos
[i
], VB
->Count
);
731 // LOCK_HARDWARE(&(rmesa->radeon));
733 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
739 reg_start(R300_VAP_PVS_WAITIDLE
,0);
742 r300EmitState(rmesa
);
744 for(i
=0; i
< VB
->PrimitiveCount
; i
++){
745 GLuint prim
= VB
->Primitive
[i
].mode
;
746 GLuint start
= VB
->Primitive
[i
].start
;
747 GLuint length
= VB
->Primitive
[i
].count
;
749 r300_render_vb_primitive_vtxfmt_a(rmesa
, ctx
, start
, start
+ length
, prim
);
752 reg_start(R300_RB3D_DSTCACHE_CTLSTAT
,0);
753 e32(0x0000000a/*0x2*/);
756 e32(0x00000003/*0x1*/);
761 // end_3d(PASS_PREFIX_VOID);
763 /* Flush state - we are done drawing.. */
764 // r300FlushCmdBufLocked(rmesa, __FUNCTION__);
765 // radeonWaitForIdleLocked(&(rmesa->radeon));
767 // UNLOCK_HARDWARE(&(rmesa->radeon));
772 #define FALLBACK_IF(expr) \
775 if (1 || RADEON_DEBUG & DEBUG_FALLBACKS) \
776 WARN_ONCE("fallback:%s\n", #expr); \
781 GLboolean
r300Fallback(GLcontext
*ctx
)
784 FALLBACK_IF(ctx
->RenderMode
!= GL_RENDER
); // We do not do SELECT or FEEDBACK (yet ?)
786 #if 0 /* These should work now.. */
787 FALLBACK_IF(ctx
->Color
.DitherFlag
);
788 FALLBACK_IF(ctx
->Color
.AlphaEnabled
); // GL_ALPHA_TEST
789 FALLBACK_IF(ctx
->Color
.BlendEnabled
); // GL_BLEND
790 FALLBACK_IF(ctx
->Polygon
.OffsetFill
); // GL_POLYGON_OFFSET_FILL
792 FALLBACK_IF(ctx
->Polygon
.OffsetPoint
); // GL_POLYGON_OFFSET_POINT
793 FALLBACK_IF(ctx
->Polygon
.OffsetLine
); // GL_POLYGON_OFFSET_LINE
794 //FALLBACK_IF(ctx->Stencil.Enabled); // GL_STENCIL_TEST
796 //FALLBACK_IF(ctx->Fog.Enabled); // GL_FOG disable as swtcl doesnt seem to support this
797 //FALLBACK_IF(ctx->Polygon.SmoothFlag); // GL_POLYGON_SMOOTH disabling to get blender going
798 FALLBACK_IF(ctx
->Polygon
.StippleFlag
); // GL_POLYGON_STIPPLE
799 FALLBACK_IF(ctx
->Multisample
.Enabled
); // GL_MULTISAMPLE_ARB
802 FALLBACK_IF(ctx
->Line
.StippleFlag
);
804 /* HW doesnt appear to directly support these */
805 FALLBACK_IF(ctx
->Line
.SmoothFlag
); // GL_LINE_SMOOTH
806 FALLBACK_IF(ctx
->Point
.SmoothFlag
); // GL_POINT_SMOOTH
807 /* Rest could be done with vertex fragments */
808 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
)
809 FALLBACK_IF(ctx
->Point
.PointSprite
); // GL_POINT_SPRITE_NV
815 * Called by the pipeline manager to render a batch of primitives.
816 * We can return true to pass on to the next stage (i.e. software
817 * rasterization) or false to indicate that the pipeline has finished
818 * after we render something.
820 static GLboolean
r300_run_render(GLcontext
*ctx
,
821 struct tnl_pipeline_stage
*stage
)
824 if (RADEON_DEBUG
& DEBUG_PRIMS
)
825 fprintf(stderr
, "%s\n", __FUNCTION__
);
827 if (r300Fallback(ctx
))
830 return r300_run_immediate_render(ctx
, stage
);
832 return r300_run_vb_render(ctx
, stage
);
836 const struct tnl_pipeline_stage _r300_render_stage
= {
842 r300_run_render
/* run */
845 static GLboolean
r300_run_tcl_render(GLcontext
*ctx
,
846 struct tnl_pipeline_stage
*stage
)
848 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
849 struct r300_vertex_program
*vp
;
851 hw_tcl_on
=future_hw_tcl_on
;
853 if (RADEON_DEBUG
& DEBUG_PRIMS
)
854 fprintf(stderr
, "%s\n", __FUNCTION__
);
855 if(hw_tcl_on
== GL_FALSE
)
858 r300UpdateShaders(rmesa
);
860 vp
= (struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
861 #if 0 /* Draw every second request with software arb vp */
864 //vp->native = GL_FALSE;
866 if (vp
->native
== GL_FALSE
) {
867 hw_tcl_on
= GL_FALSE
;
870 //r300UpdateShaderStates(rmesa);
872 return r300_run_vb_render(ctx
, stage
);
875 const struct tnl_pipeline_stage _r300_tcl_stage
= {
881 r300_run_tcl_render
/* run */
884 /* R300 texture rectangle expects coords in 0..1 range, not 0..dimension
885 * as in the extension spec. Need to translate here.
887 * Note that swrast expects 0..dimension, so if a fallback is active,
888 * don't do anything. (Maybe need to configure swrast to match hw)
890 struct texrect_stage_data
{
891 GLvector4f texcoord
[MAX_TEXTURE_UNITS
];
894 #define TEXRECT_STAGE_DATA(stage) ((struct texrect_stage_data *)stage->privatePtr)
897 static GLboolean
run_texrect_stage( GLcontext
*ctx
,
898 struct tnl_pipeline_stage
*stage
)
900 struct texrect_stage_data
*store
= TEXRECT_STAGE_DATA(stage
);
901 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
902 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
903 struct vertex_buffer
*VB
= &tnl
->vb
;
906 if (rmesa
->radeon
.Fallback
)
909 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
910 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
& TEXTURE_RECT_BIT
) {
911 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
].CurrentRect
;
912 struct gl_texture_image
*texImage
= texObj
->Image
[0][texObj
->BaseLevel
];
913 const GLfloat iw
= 1.0/texImage
->Width
;
914 const GLfloat ih
= 1.0/texImage
->Height
;
915 GLfloat
*in
= (GLfloat
*)VB
->TexCoordPtr
[i
]->data
;
916 GLint instride
= VB
->TexCoordPtr
[i
]->stride
;
917 GLfloat (*out
)[4] = store
->texcoord
[i
].data
;
920 store
->texcoord
[i
].size
= VB
->TexCoordPtr
[i
]->size
;
921 for (j
= 0 ; j
< VB
->Count
; j
++) {
922 switch (VB
->TexCoordPtr
[i
]->size
) {
930 out
[j
][0] = in
[0] * iw
;
931 out
[j
][1] = in
[1] * ih
;
933 in
= (GLfloat
*)((GLubyte
*)in
+ instride
);
936 VB
->AttribPtr
[VERT_ATTRIB_TEX0
+i
] = VB
->TexCoordPtr
[i
] = &store
->texcoord
[i
];
944 /* Called the first time stage->run() is invoked.
946 static GLboolean
alloc_texrect_data( GLcontext
*ctx
,
947 struct tnl_pipeline_stage
*stage
)
949 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
950 struct texrect_stage_data
*store
;
953 stage
->privatePtr
= CALLOC(sizeof(*store
));
954 store
= TEXRECT_STAGE_DATA(stage
);
958 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
959 _mesa_vector4f_alloc( &store
->texcoord
[i
], 0, VB
->Size
, 32 );
964 static void free_texrect_data( struct tnl_pipeline_stage
*stage
)
966 struct texrect_stage_data
*store
= TEXRECT_STAGE_DATA(stage
);
970 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++)
971 if (store
->texcoord
[i
].data
)
972 _mesa_vector4f_free( &store
->texcoord
[i
] );
974 stage
->privatePtr
= NULL
;
978 const struct tnl_pipeline_stage _r300_texrect_stage
=
980 "r300 texrect stage", /* name */