1 /**************************************************************************
3 Copyright (C) 2007 Dave Airlie
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 THE COPYRIGHT OWNER(S) AND/OR ITS 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 * Dave Airlie <airlied@linux.ie>
31 * Maciej Cencora <m.cencora@gmail.com>
35 #include "tnl/t_pipeline.h"
37 #include "r300_state.h"
38 #include "r300_swtcl.h"
39 #include "r300_emit.h"
42 #define EMIT_ATTR( ATTR, STYLE ) \
44 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
45 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
46 rmesa->radeon.swtcl.vertex_attr_count++; \
49 #define EMIT_PAD( N ) \
51 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
52 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
53 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
54 rmesa->radeon.swtcl.vertex_attr_count++; \
57 #define ADD_ATTR(_attr, _format, _dst_loc, _swizzle, _write_mask) \
59 attrs[num_attrs].attr = (_attr); \
60 attrs[num_attrs].format = (_format); \
61 attrs[num_attrs].dst_loc = (_dst_loc); \
62 attrs[num_attrs].swizzle = (_swizzle); \
63 attrs[num_attrs].write_mask = (_write_mask); \
67 static void r300SwtclVAPSetup(GLcontext
*ctx
, GLuint InputsRead
, GLuint OutputsWritten
, GLuint vap_out_fmt_1
)
69 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
70 struct vertex_attribute
*attrs
= rmesa
->swtcl
.vert_attrs
;
72 uint32_t *vir0
= &rmesa
->hw
.vir
[0].cmd
[1];
73 uint32_t *vir1
= &rmesa
->hw
.vir
[1].cmd
[1];
75 for (i
= 0; i
< R300_VIR_CMDSIZE
-1; ++i
)
76 vir0
[i
] = vir1
[i
] = 0;
78 for (i
= 0, j
= 0; i
< rmesa
->radeon
.swtcl
.vertex_attr_count
; ++i
) {
80 switch (attrs
[i
].format
) {
82 data_format
= R300_DATA_TYPE_FLOAT_1
;
85 data_format
= R300_DATA_TYPE_FLOAT_2
;
88 data_format
= R300_DATA_TYPE_FLOAT_3
;
91 data_format
= R300_DATA_TYPE_FLOAT_4
;
93 case EMIT_4UB_4F_RGBA
:
94 case EMIT_4UB_4F_ABGR
:
95 data_format
= R300_DATA_TYPE_BYTE
| R300_NORMALIZE
;
98 fprintf(stderr
, "%s: Invalid data format type", __FUNCTION__
);
103 tmp
= data_format
| (attrs
[i
].dst_loc
<< R300_DST_VEC_LOC_SHIFT
);
105 vir0
[j
] = tmp
<< R300_DATA_TYPE_0_SHIFT
;
106 vir1
[j
] = attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
);
108 vir0
[j
] |= tmp
<< R300_DATA_TYPE_1_SHIFT
;
109 vir1
[j
] |= (attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
)) << R300_SWIZZLE1_SHIFT
;
114 reg_count
= (rmesa
->radeon
.swtcl
.vertex_attr_count
+ 1) >> 1;
115 if (rmesa
->radeon
.swtcl
.vertex_attr_count
% 2 != 0) {
116 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_0_SHIFT
;
118 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_1_SHIFT
;
121 R300_STATECHANGE(rmesa
, vir
[0]);
122 R300_STATECHANGE(rmesa
, vir
[1]);
123 R300_STATECHANGE(rmesa
, vof
);
124 R300_STATECHANGE(rmesa
, vic
);
126 if (rmesa
->radeon
.radeonScreen
->kernel_mm
) {
127 rmesa
->hw
.vir
[0].cmd
[0] &= 0xC000FFFF;
128 rmesa
->hw
.vir
[1].cmd
[0] &= 0xC000FFFF;
129 rmesa
->hw
.vir
[0].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
130 rmesa
->hw
.vir
[1].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
132 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
= reg_count
;
133 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
= reg_count
;
136 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
137 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
138 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
140 * Can't use r300VAPOutputCntl1 function because it assumes
141 * that all texture coords have 4 components and that's the case
142 * for HW TCL path, but not for SW TCL.
144 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = vap_out_fmt_1
;
148 static void r300SetVertexFormat( GLcontext
*ctx
)
150 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
151 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
152 struct vertex_buffer
*VB
= &tnl
->vb
;
153 int first_free_tex
= 0, vap_out_fmt_1
= 0;
154 GLuint InputsRead
= 0;
155 GLuint OutputsWritten
= 0;
157 struct vertex_attribute
*attrs
= rmesa
->swtcl
.vert_attrs
;
159 rmesa
->swtcl
.coloroffset
= rmesa
->swtcl
.specoffset
= 0;
160 rmesa
->radeon
.swtcl
.vertex_attr_count
= 0;
162 /* We always want non Ndc coords format */
163 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
165 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_POS
)) {
166 InputsRead
|= 1 << VERT_ATTRIB_POS
;
167 OutputsWritten
|= 1 << VERT_RESULT_HPOS
;
168 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
);
169 ADD_ATTR(VERT_ATTRIB_POS
, EMIT_4F
, SWTCL_OVM_POS
, SWIZZLE_XYZW
, MASK_XYZW
);
170 rmesa
->swtcl
.coloroffset
= 4;
173 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_COLOR0
)) {
174 InputsRead
|= 1 << VERT_ATTRIB_COLOR0
;
175 OutputsWritten
|= 1 << VERT_RESULT_COL0
;
176 #if MESA_LITTLE_ENDIAN
177 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
);
178 ADD_ATTR(VERT_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
, SWTCL_OVM_COLOR0
, SWIZZLE_XYZW
, MASK_XYZW
);
180 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
);
181 ADD_ATTR(VERT_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
, SWTCL_OVM_COLOR0
, SWIZZLE_XYZW
, MASK_XYZW
);
185 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_COLOR1
)) {
186 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
187 InputsRead
|= 1 << VERT_ATTRIB_COLOR1
;
188 OutputsWritten
|= 1 << VERT_RESULT_COL1
;
189 #if MESA_LITTLE_ENDIAN
190 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_4UB_4F_RGBA
);
191 ADD_ATTR(VERT_ATTRIB_COLOR1
, EMIT_4UB_4F_RGBA
, SWTCL_OVM_COLOR1
, swiz
, MASK_XYZW
);
193 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_4UB_4F_ABGR
);
194 ADD_ATTR(VERT_ATTRIB_COLOR1
, EMIT_4UB_4F_ABGR
, SWTCL_OVM_COLOR1
, swiz
, MASK_XYZW
);
196 rmesa
->swtcl
.specoffset
= rmesa
->swtcl
.coloroffset
+ 1;
199 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
200 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ZERO
);
201 InputsRead
|= 1 << VERT_ATTRIB_POINT_SIZE
;
202 OutputsWritten
|= 1 << VERT_RESULT_PSIZ
;
203 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
);
204 ADD_ATTR(VERT_ATTRIB_POINT_SIZE
, EMIT_1F
, SWTCL_OVM_POINT_SIZE
, swiz
, MASK_X
);
207 if (RENDERINPUTS_TEST_RANGE(tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
209 GLuint swiz
, mask
, format
;
210 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
211 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_TEX(i
) )) {
212 switch (VB
->TexCoordPtr
[i
]->size
) {
215 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
220 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
221 mask
= MASK_X
| MASK_Y
;
226 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
227 mask
= MASK_X
| MASK_Y
| MASK_Z
;
239 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ i
);
240 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ i
);
241 EMIT_ATTR(_TNL_ATTRIB_TEX(i
), format
);
242 ADD_ATTR(VERT_ATTRIB_TEX0
+ i
, format
, SWTCL_OVM_TEX(i
), swiz
, mask
);
243 vap_out_fmt_1
|= size
<< (i
* 3);
249 /* RS can't put fragment position on the pixel stack, so stuff it in texcoord if needed */
250 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_POS
) && (ctx
->FragmentProgram
._Current
->Base
.InputsRead
& FRAG_BIT_WPOS
)) {
251 if (first_free_tex
>= ctx
->Const
.MaxTextureUnits
) {
252 fprintf(stderr
, "\tout of free texcoords to write w pos\n");
256 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ first_free_tex
);
257 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ first_free_tex
);
258 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
);
259 ADD_ATTR(VERT_ATTRIB_POS
, EMIT_4F
, SWTCL_OVM_TEX(first_free_tex
), SWIZZLE_XYZW
, MASK_XYZW
);
260 vap_out_fmt_1
|= 4 << (first_free_tex
* 3);
264 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_FOG
)) {
265 if (first_free_tex
>= ctx
->Const
.MaxTextureUnits
) {
266 fprintf(stderr
, "\tout of free texcoords to write fog coordinate\n");
270 InputsRead
|= 1 << VERT_ATTRIB_FOG
;
271 OutputsWritten
|= 1 << VERT_RESULT_FOGC
;
272 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ZERO
);
273 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1F
);
274 ADD_ATTR(VERT_ATTRIB_FOG
, EMIT_1F
, SWTCL_OVM_TEX(first_free_tex
), swiz
, MASK_X
);
275 vap_out_fmt_1
|= 1 << (first_free_tex
* 3);
279 r300SwtclVAPSetup(ctx
, InputsRead
, OutputsWritten
, vap_out_fmt_1
);
281 rmesa
->radeon
.swtcl
.vertex_size
=
282 _tnl_install_attrs( ctx
,
283 rmesa
->radeon
.swtcl
.vertex_attrs
,
284 rmesa
->radeon
.swtcl
.vertex_attr_count
,
287 rmesa
->radeon
.swtcl
.vertex_size
/= 4;
289 RENDERINPUTS_COPY(rmesa
->render_inputs_bitset
, tnl
->render_inputs_bitset
);
293 static GLuint reduced_prim
[] = {
306 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint prim
);
307 static void r300RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
309 /***********************************************************************
310 * Emit primitives as inline vertices *
311 ***********************************************************************/
314 #define HAVE_POINTS 1
316 #define HAVE_LINE_STRIPS 1
317 #define HAVE_TRIANGLES 1
318 #define HAVE_TRI_STRIPS 1
319 #define HAVE_TRI_STRIP_1 0
320 #define HAVE_TRI_FANS 1
322 #define HAVE_QUAD_STRIPS 0
323 #define HAVE_POLYGONS 1
328 #define CTX_ARG r300ContextPtr rmesa
329 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
330 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
332 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
333 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
334 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
335 #define VERTEX r300Vertex
337 #define TAG(x) r300_##x
338 #include "tnl_dd/t_dd_triemit.h"
342 /***********************************************************************
343 * Macros for t_dd_tritmp.h to draw basic primitives *
344 ***********************************************************************/
346 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
347 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
348 #define LINE( a, b ) r300_line( rmesa, a, b )
349 #define POINT( a ) r300_point( rmesa, a )
351 /***********************************************************************
352 * Build render functions from dd templates *
353 ***********************************************************************/
355 #define R300_TWOSIDE_BIT 0x01
356 #define R300_UNFILLED_BIT 0x02
357 #define R300_MAX_TRIFUNC 0x04
360 tnl_points_func points
;
362 tnl_triangle_func triangle
;
364 } rast_tab
[R300_MAX_TRIFUNC
];
366 #define DO_FALLBACK 0
367 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
368 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
375 #define DO_FULL_QUAD 1
379 #define HAVE_BACK_COLORS 0
380 #define HAVE_HW_FLATSHADE 1
383 #define DEPTH_SCALE 1.0
384 #define UNFILLED_TRI unfilled_tri
385 #define UNFILLED_QUAD unfilled_quad
386 #define VERT_X(_v) _v->v.x
387 #define VERT_Y(_v) _v->v.y
388 #define VERT_Z(_v) _v->v.z
389 #define AREA_IS_CCW( a ) (a < 0)
390 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
392 #define VERT_SET_RGBA( v, c ) \
394 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
395 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
396 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
397 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
398 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
401 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
403 #define VERT_SET_SPEC( v0, c ) \
406 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
407 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
408 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
412 #define VERT_COPY_SPEC( v0, v1 ) \
415 v0->v.specular.red = v1->v.specular.red; \
416 v0->v.specular.green = v1->v.specular.green; \
417 v0->v.specular.blue = v1->v.specular.blue; \
421 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
422 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
423 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
424 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
430 #define LOCAL_VARS(n) \
431 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
432 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
433 GLuint coloroffset = rmesa->swtcl.coloroffset; \
434 GLuint specoffset = rmesa->swtcl.specoffset; \
435 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
437 /***********************************************************************
438 * Helpers for rendering unfilled primitives *
439 ***********************************************************************/
441 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
442 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
445 #include "tnl_dd/t_dd_unfilled.h"
449 /***********************************************************************
450 * Generate GL render functions *
451 ***********************************************************************/
456 #include "tnl_dd/t_dd_tritmp.h"
458 #define IND (R300_TWOSIDE_BIT)
459 #define TAG(x) x##_twoside
460 #include "tnl_dd/t_dd_tritmp.h"
462 #define IND (R300_UNFILLED_BIT)
463 #define TAG(x) x##_unfilled
464 #include "tnl_dd/t_dd_tritmp.h"
466 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
467 #define TAG(x) x##_twoside_unfilled
468 #include "tnl_dd/t_dd_tritmp.h"
472 static void init_rast_tab( void )
477 init_twoside_unfilled();
480 /**********************************************************************/
481 /* Render unclipped begin/end objects */
482 /**********************************************************************/
484 #define RENDER_POINTS( start, count ) \
485 for ( ; start < count ; start++) \
486 r300_point( rmesa, VERT(start) )
487 #define RENDER_LINE( v0, v1 ) \
488 r300_line( rmesa, VERT(v0), VERT(v1) )
489 #define RENDER_TRI( v0, v1, v2 ) \
490 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
491 #define RENDER_QUAD( v0, v1, v2, v3 ) \
492 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
493 #define INIT(x) do { \
494 r300RenderPrimitive( ctx, x ); \
498 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
499 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
500 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
501 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
502 const GLboolean stipple = ctx->Line.StippleFlag; \
503 (void) elt; (void) stipple;
504 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
505 #define RESET_OCCLUSION
506 #define PRESERVE_VB_DEFS
508 #define TAG(x) r300_##x##_verts
509 #include "tnl/t_vb_rendertmp.h"
512 #define TAG(x) r300_##x##_elts
513 #define ELT(x) elt[x]
514 #include "tnl/t_vb_rendertmp.h"
519 /**********************************************************************/
520 /* Choose render functions */
521 /**********************************************************************/
522 static void r300ChooseRenderState( GLcontext
*ctx
)
524 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
525 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
527 GLuint flags
= ctx
->_TriangleCaps
;
529 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R300_TWOSIDE_BIT
;
530 if (flags
& DD_TRI_UNFILLED
) index
|= R300_UNFILLED_BIT
;
532 if (index
!= rmesa
->radeon
.swtcl
.RenderIndex
) {
533 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
534 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
535 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
536 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
537 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
540 tnl
->Driver
.Render
.PrimTabVerts
= r300_render_tab_verts
;
541 tnl
->Driver
.Render
.PrimTabElts
= r300_render_tab_elts
;
542 tnl
->Driver
.Render
.ClippedPolygon
= r300_fast_clipped_poly
;
544 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
545 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
546 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
549 rmesa
->radeon
.swtcl
.RenderIndex
= index
;
554 static void r300RenderStart(GLcontext
*ctx
)
556 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
558 r300ChooseRenderState(ctx
);
559 r300SetVertexFormat(ctx
);
561 r300ValidateBuffers(ctx
);
563 r300UpdateShaders(rmesa
);
564 r300UpdateShaderStates(rmesa
);
566 r300EmitCacheFlush(rmesa
);
568 /* investigate if we can put back flush optimisation if needed */
569 if (rmesa
->radeon
.dma
.flush
!= NULL
) {
570 rmesa
->radeon
.dma
.flush(ctx
);
574 static void r300RenderFinish(GLcontext
*ctx
)
578 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
580 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
582 if (rmesa
->radeon
.swtcl
.hw_primitive
!= hwprim
) {
583 R300_NEWPRIM( rmesa
);
584 rmesa
->radeon
.swtcl
.hw_primitive
= hwprim
;
588 static void r300RenderPrimitive(GLcontext
*ctx
, GLenum prim
)
591 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
592 rmesa
->radeon
.swtcl
.render_primitive
= prim
;
594 if ((prim
== GL_TRIANGLES
) && (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
597 r300RasterPrimitive( ctx
, reduced_prim
[prim
] );
600 static void r300ResetLineStipple(GLcontext
*ctx
)
604 void r300InitSwtcl(GLcontext
*ctx
)
606 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
607 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
608 static int firsttime
= 1;
615 tnl
->Driver
.Render
.Start
= r300RenderStart
;
616 tnl
->Driver
.Render
.Finish
= r300RenderFinish
;
617 tnl
->Driver
.Render
.PrimitiveNotify
= r300RenderPrimitive
;
618 tnl
->Driver
.Render
.ResetLineStipple
= r300ResetLineStipple
;
619 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
620 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
621 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
623 /* FIXME: what are these numbers? */
624 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
625 48 * sizeof(GLfloat
) );
627 rmesa
->radeon
.swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
628 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
629 rmesa
->radeon
.swtcl
.render_primitive
= GL_TRIANGLES
;
630 rmesa
->radeon
.swtcl
.hw_primitive
= 0;
632 _tnl_invalidate_vertex_state( ctx
, ~0 );
633 _tnl_invalidate_vertices( ctx
, ~0 );
635 _tnl_need_projected_coords( ctx
, GL_FALSE
);
636 r300ChooseRenderState(ctx
);
639 void r300DestroySwtcl(GLcontext
*ctx
)
643 static void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, struct radeon_bo
*bo
, GLuint offset
)
645 BATCH_LOCALS(&rmesa
->radeon
);
647 if (RADEON_DEBUG
& DEBUG_VERTS
)
648 fprintf(stderr
, "%s: vertex_size %d, offset 0x%x \n",
649 __FUNCTION__
, vertex_size
, offset
);
652 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR
, 2);
654 OUT_BATCH(vertex_size
| (vertex_size
<< 8));
655 OUT_BATCH_RELOC(offset
, bo
, offset
, RADEON_GEM_DOMAIN_GTT
, 0, 0);
659 static void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
)
661 BATCH_LOCALS(&rmesa
->radeon
);
664 type
= r300PrimitiveType(rmesa
, primitive
);
665 num_verts
= r300NumVerts(rmesa
, vertex_nr
, primitive
);
668 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
669 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (num_verts
<< 16) | type
);
673 void r300_swtcl_flush(GLcontext
*ctx
, uint32_t current_offset
)
675 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
677 rcommonEnsureCmdBufSpace(&rmesa
->radeon
,
678 rmesa
->radeon
.hw
.max_state_size
+ (12*sizeof(int)),
680 radeonEmitState(&rmesa
->radeon
);
681 r300EmitVertexAOS(rmesa
,
682 rmesa
->radeon
.swtcl
.vertex_size
,
683 rmesa
->radeon
.dma
.current
,
686 r300EmitVbufPrim(rmesa
,
687 rmesa
->radeon
.swtcl
.hw_primitive
,
688 rmesa
->radeon
.swtcl
.numverts
);
689 r300EmitCacheFlush(rmesa
);