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"
41 #include "r300_render.h"
42 #include "main/simple_list.h"
44 #define EMIT_ATTR( ATTR, STYLE ) \
46 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
47 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
48 rmesa->radeon.swtcl.vertex_attr_count++; \
51 #define EMIT_PAD( N ) \
53 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
54 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
55 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
56 rmesa->radeon.swtcl.vertex_attr_count++; \
59 #define ADD_ATTR(_attr, _format, _dst_loc, _swizzle, _write_mask, _normalize) \
61 attrs[num_attrs].element = (_attr); \
62 attrs[num_attrs].data_type = (_format); \
63 attrs[num_attrs].dst_loc = (_dst_loc); \
64 attrs[num_attrs].swizzle = (_swizzle); \
65 attrs[num_attrs].write_mask = (_write_mask); \
66 attrs[num_attrs]._signed = 0; \
67 attrs[num_attrs].normalize = (_normalize); \
71 void r300ChooseSwtclVertexFormat(GLcontext
*ctx
, GLuint
*_InputsRead
, GLuint
*_OutputsWritten
)
73 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
74 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
75 struct vertex_buffer
*VB
= &tnl
->vb
;
76 int first_free_tex
= 0;
77 GLuint InputsRead
= 0;
78 GLuint OutputsWritten
= 0;
80 GLuint fp_reads
= rmesa
->selected_fp
->InputsRead
;
81 struct vertex_attribute
*attrs
= rmesa
->vbuf
.attribs
;
83 rmesa
->swtcl
.coloroffset
= rmesa
->swtcl
.specoffset
= 0;
84 rmesa
->radeon
.swtcl
.vertex_attr_count
= 0;
86 if (RADEON_DEBUG
& DEBUG_VERTS
)
87 fprintf(stderr
, "%s\n", __func__
);
89 /* We always want non Ndc coords format */
90 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
92 /* Always write position vector */
93 InputsRead
|= 1 << VERT_ATTRIB_POS
;
94 OutputsWritten
|= 1 << VERT_RESULT_HPOS
;
95 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
);
96 ADD_ATTR(VERT_ATTRIB_POS
, R300_DATA_TYPE_FLOAT_4
, SWTCL_OVM_POS
, SWIZZLE_XYZW
, MASK_XYZW
, 0);
97 rmesa
->swtcl
.coloroffset
= 4;
99 if (fp_reads
& FRAG_BIT_COL0
) {
100 InputsRead
|= 1 << VERT_ATTRIB_COLOR0
;
101 OutputsWritten
|= 1 << VERT_RESULT_COL0
;
102 #if MESA_LITTLE_ENDIAN
103 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
);
104 ADD_ATTR(VERT_ATTRIB_COLOR0
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR0
, SWIZZLE_XYZW
, MASK_XYZW
, 1);
106 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
);
107 ADD_ATTR(VERT_ATTRIB_COLOR0
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR0
, SWIZZLE_XYZW
, MASK_XYZW
, 1);
111 if (fp_reads
& FRAG_BIT_COL1
) {
112 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
113 InputsRead
|= 1 << VERT_ATTRIB_COLOR1
;
114 OutputsWritten
|= 1 << VERT_RESULT_COL1
;
115 #if MESA_LITTLE_ENDIAN
116 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_4UB_4F_RGBA
);
117 ADD_ATTR(VERT_ATTRIB_COLOR1
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR1
, swiz
, MASK_XYZW
, 1);
119 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_4UB_4F_ABGR
);
120 ADD_ATTR(VERT_ATTRIB_COLOR1
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR1
, swiz
, MASK_XYZW
, 1);
122 rmesa
->swtcl
.specoffset
= rmesa
->swtcl
.coloroffset
+ 1;
125 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
) {
126 VB
->AttribPtr
[VERT_ATTRIB_GENERIC0
] = VB
->ColorPtr
[1];
127 OutputsWritten
|= 1 << VERT_RESULT_BFC0
;
128 #if MESA_LITTLE_ENDIAN
129 EMIT_ATTR( _TNL_ATTRIB_GENERIC0
, EMIT_4UB_4F_RGBA
);
130 ADD_ATTR(VERT_ATTRIB_GENERIC0
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR2
, SWIZZLE_XYZW
, MASK_XYZW
, 1);
132 EMIT_ATTR( _TNL_ATTRIB_GENERIC0
, EMIT_4UB_4F_ABGR
);
133 ADD_ATTR(VERT_ATTRIB_GENERIC0
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR2
, SWIZZLE_XYZW
, MASK_XYZW
, 1);
135 if (fp_reads
& FRAG_BIT_COL1
) {
136 VB
->AttribPtr
[VERT_ATTRIB_GENERIC1
] = VB
->SecondaryColorPtr
[1];
137 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
138 OutputsWritten
|= 1 << VERT_RESULT_BFC1
;
139 #if MESA_LITTLE_ENDIAN
140 EMIT_ATTR( _TNL_ATTRIB_GENERIC1
, EMIT_4UB_4F_RGBA
);
141 ADD_ATTR(VERT_ATTRIB_GENERIC1
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR3
, swiz
, MASK_XYZW
, 1);
143 EMIT_ATTR( _TNL_ATTRIB_GENERIC1
, EMIT_4UB_4F_ABGR
);
144 ADD_ATTR(VERT_ATTRIB_GENERIC1
, R300_DATA_TYPE_BYTE
, SWTCL_OVM_COLOR3
, swiz
, MASK_XYZW
, 1);
149 if (RENDERINPUTS_TEST(tnl
->render_inputs_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
150 GLuint swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ZERO
);
151 InputsRead
|= 1 << VERT_ATTRIB_POINT_SIZE
;
152 OutputsWritten
|= 1 << VERT_RESULT_PSIZ
;
153 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
);
154 ADD_ATTR(VERT_ATTRIB_POINT_SIZE
, R300_DATA_TYPE_FLOAT_1
, SWTCL_OVM_POINT_SIZE
, swiz
, MASK_X
, 0);
157 if (rmesa
->selected_fp
->wpos_attr
!= FRAG_ATTRIB_MAX
) {
158 int tex_id
= rmesa
->selected_fp
->wpos_attr
- FRAG_ATTRIB_TEX0
;
160 VB
->AttribPtr
[VERT_ATTRIB_TEX0
+ tex_id
] = VB
->AttribPtr
[VERT_ATTRIB_POS
];
161 VB
->TexCoordPtr
[tex_id
] = VB
->AttribPtr
[VERT_ATTRIB_POS
];
162 RENDERINPUTS_SET(tnl
->render_inputs_bitset
, _TNL_ATTRIB_TEX0
+ tex_id
);
165 if (rmesa
->selected_fp
->fog_attr
!= FRAG_ATTRIB_MAX
) {
166 int tex_id
= rmesa
->selected_fp
->fog_attr
- FRAG_ATTRIB_TEX0
;
168 VB
->AttribPtr
[VERT_ATTRIB_TEX0
+ tex_id
] = VB
->AttribPtr
[VERT_ATTRIB_FOG
];
169 VB
->TexCoordPtr
[tex_id
] = VB
->AttribPtr
[VERT_ATTRIB_FOG
];
170 RENDERINPUTS_SET(tnl
->render_inputs_bitset
, _TNL_ATTRIB_TEX0
+ tex_id
);
174 * Sending only one texcoord component may lead to lock up,
175 * so for all textures always output 4 texcoord components to RS.
179 GLuint swiz
, format
, hw_format
;
180 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
181 if (fp_reads
& FRAG_BIT_TEX(i
)) {
182 switch (VB
->TexCoordPtr
[i
]->size
) {
185 hw_format
= R300_DATA_TYPE_FLOAT_1
;
186 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_ZERO
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
190 hw_format
= R300_DATA_TYPE_FLOAT_2
;
191 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_ZERO
, SWIZZLE_ONE
);
195 hw_format
= R300_DATA_TYPE_FLOAT_3
;
196 swiz
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
);
200 hw_format
= R300_DATA_TYPE_FLOAT_4
;
206 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ i
);
207 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ i
);
208 EMIT_ATTR(_TNL_ATTRIB_TEX(i
), format
);
209 ADD_ATTR(VERT_ATTRIB_TEX0
+ i
, hw_format
, SWTCL_OVM_TEX(first_free_tex
), swiz
, MASK_XYZW
, 0);
215 if (first_free_tex
>= ctx
->Const
.MaxTextureUnits
) {
216 fprintf(stderr
, "\tout of free texcoords to write fog coordinate\n");
221 rmesa
->vbuf
.num_attribs
= num_attrs
;
222 *_InputsRead
= InputsRead
;
223 *_OutputsWritten
= OutputsWritten
;
225 RENDERINPUTS_COPY(rmesa
->render_inputs_bitset
, tnl
->render_inputs_bitset
);
228 static void r300PrepareVertices(GLcontext
*ctx
)
230 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
231 GLuint InputsRead
, OutputsWritten
;
233 r300ChooseSwtclVertexFormat(ctx
, &InputsRead
, &OutputsWritten
);
234 r300SetupVAP(ctx
, InputsRead
, OutputsWritten
);
236 rmesa
->radeon
.swtcl
.vertex_size
=
237 _tnl_install_attrs( ctx
,
238 rmesa
->radeon
.swtcl
.vertex_attrs
,
239 rmesa
->radeon
.swtcl
.vertex_attr_count
,
242 rmesa
->radeon
.swtcl
.vertex_size
/= 4;
246 static GLuint reduced_prim
[] = {
259 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint prim
);
261 /***********************************************************************
262 * Emit primitives as inline vertices *
263 ***********************************************************************/
266 #define HAVE_POINTS 1
268 #define HAVE_LINE_STRIPS 1
269 #define HAVE_TRIANGLES 1
270 #define HAVE_TRI_STRIPS 1
271 #define HAVE_TRI_STRIP_1 0
272 #define HAVE_TRI_FANS 1
274 #define HAVE_QUAD_STRIPS 0
275 #define HAVE_POLYGONS 1
280 #define CTX_ARG r300ContextPtr rmesa
281 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
282 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
284 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
285 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
286 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
287 #define VERTEX r300Vertex
289 #define TAG(x) r300_##x
290 #include "tnl_dd/t_dd_triemit.h"
294 /***********************************************************************
295 * Macros for t_dd_tritmp.h to draw basic primitives *
296 ***********************************************************************/
298 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
299 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
300 #define LINE( a, b ) r300_line( rmesa, a, b )
301 #define POINT( a ) r300_point( rmesa, a )
303 /***********************************************************************
304 * Build render functions from dd templates *
305 ***********************************************************************/
307 #define R300_UNFILLED_BIT 0x01
308 #define R300_MAX_TRIFUNC 0x02
311 tnl_points_func points
;
313 tnl_triangle_func triangle
;
315 } rast_tab
[R300_MAX_TRIFUNC
];
317 #define DO_FALLBACK 0
318 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
326 #define DO_FULL_QUAD 1
330 #define HAVE_BACK_COLORS 0
331 #define HAVE_HW_FLATSHADE 1
334 #define DEPTH_SCALE 1.0
335 #define UNFILLED_TRI unfilled_tri
336 #define UNFILLED_QUAD unfilled_quad
337 #define VERT_X(_v) _v->v.x
338 #define VERT_Y(_v) _v->v.y
339 #define VERT_Z(_v) _v->v.z
340 #define AREA_IS_CCW( a ) (a < 0)
341 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
343 #define VERT_SET_RGBA( v, c ) \
345 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
346 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
347 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
348 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
349 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
352 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
354 #define VERT_SET_SPEC( v0, c ) \
357 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
358 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
359 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
363 #define VERT_COPY_SPEC( v0, v1 ) \
366 v0->v.specular.red = v1->v.specular.red; \
367 v0->v.specular.green = v1->v.specular.green; \
368 v0->v.specular.blue = v1->v.specular.blue; \
372 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
373 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
374 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
375 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
381 #define LOCAL_VARS(n) \
382 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
383 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
384 GLuint coloroffset = rmesa->swtcl.coloroffset; \
385 GLuint specoffset = rmesa->swtcl.specoffset; \
386 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
388 /***********************************************************************
389 * Helpers for rendering unfilled primitives *
390 ***********************************************************************/
392 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
393 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
396 #include "tnl_dd/t_dd_unfilled.h"
400 /***********************************************************************
401 * Generate GL render functions *
402 ***********************************************************************/
407 #include "tnl_dd/t_dd_tritmp.h"
409 #define IND (R300_UNFILLED_BIT)
410 #define TAG(x) x##_unfilled
411 #include "tnl_dd/t_dd_tritmp.h"
414 static void init_rast_tab( void )
420 /**********************************************************************/
421 /* Render unclipped begin/end objects */
422 /**********************************************************************/
424 #define RENDER_POINTS( start, count ) \
425 for ( ; start < count ; start++) \
426 r300_point( rmesa, VERT(start) )
427 #define RENDER_LINE( v0, v1 ) \
428 r300_line( rmesa, VERT(v0), VERT(v1) )
429 #define RENDER_TRI( v0, v1, v2 ) \
430 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
431 #define RENDER_QUAD( v0, v1, v2, v3 ) \
432 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
433 #define INIT(x) do { \
434 r300RenderPrimitive( ctx, x ); \
438 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
439 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
440 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
441 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
442 const GLboolean stipple = ctx->Line.StippleFlag; \
443 (void) elt; (void) stipple;
444 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
445 #define RESET_OCCLUSION
446 #define PRESERVE_VB_DEFS
448 #define TAG(x) r300_##x##_verts
449 #include "tnl/t_vb_rendertmp.h"
452 #define TAG(x) r300_##x##_elts
453 #define ELT(x) elt[x]
454 #include "tnl/t_vb_rendertmp.h"
459 /**********************************************************************/
460 /* Choose render functions */
461 /**********************************************************************/
462 static void r300ChooseRenderState( GLcontext
*ctx
)
464 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
465 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
467 GLuint flags
= ctx
->_TriangleCaps
;
468 if (RADEON_DEBUG
& DEBUG_VERTS
)
469 fprintf(stderr
, "%s\n", __func__
);
471 if (flags
& DD_TRI_UNFILLED
) index
|= R300_UNFILLED_BIT
;
473 if (index
!= rmesa
->radeon
.swtcl
.RenderIndex
) {
474 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
475 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
476 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
477 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
478 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
481 tnl
->Driver
.Render
.PrimTabVerts
= r300_render_tab_verts
;
482 tnl
->Driver
.Render
.PrimTabElts
= r300_render_tab_elts
;
483 tnl
->Driver
.Render
.ClippedPolygon
= r300_fast_clipped_poly
;
485 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
486 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
487 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
490 rmesa
->radeon
.swtcl
.RenderIndex
= index
;
495 void r300RenderStart(GLcontext
*ctx
)
497 if (RADEON_DEBUG
& DEBUG_VERTS
)
498 fprintf(stderr
, "%s\n", __func__
);
499 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
501 r300ChooseRenderState(ctx
);
503 r300UpdateShaders(rmesa
);
505 r300PrepareVertices(ctx
);
507 r300ValidateBuffers(ctx
);
509 r300UpdateShaderStates(rmesa
);
511 const int vertex_size
= 7;
512 const int prim_size
= 3;
514 if (!rmesa
->radeon
.swtcl
.primitive_counter
) {
515 if (rcommonEnsureCmdBufSpace(&rmesa
->radeon
,
516 radeonCountStateEmitSize(&rmesa
->radeon
) +
517 + vertex_size
+ prim_size
,
519 rmesa
->radeon
.swtcl
.primitive_counter
= 0;
521 rmesa
->radeon
.swtcl
.primitive_counter
= 1;
524 r300EmitCacheFlush(rmesa
);
526 /* investigate if we can put back flush optimisation if needed */
527 if (rmesa
->radeon
.dma
.flush
!= NULL
) {
528 rmesa
->radeon
.dma
.flush(ctx
);
532 void r300RenderFinish(GLcontext
*ctx
)
536 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
538 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
539 if (RADEON_DEBUG
& DEBUG_VERTS
)
540 fprintf(stderr
, "%s\n", __func__
);
542 if (rmesa
->radeon
.swtcl
.hw_primitive
!= hwprim
) {
543 R300_NEWPRIM( rmesa
);
544 rmesa
->radeon
.swtcl
.hw_primitive
= hwprim
;
548 void r300RenderPrimitive(GLcontext
*ctx
, GLenum prim
)
551 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
552 rmesa
->radeon
.swtcl
.render_primitive
= prim
;
553 if (RADEON_DEBUG
& DEBUG_VERTS
)
554 fprintf(stderr
, "%s\n", __func__
);
556 if ((prim
== GL_TRIANGLES
) && (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
559 r300RasterPrimitive( ctx
, reduced_prim
[prim
] );
562 void r300ResetLineStipple(GLcontext
*ctx
)
564 if (RADEON_DEBUG
& DEBUG_VERTS
)
565 fprintf(stderr
, "%s\n", __func__
);
568 void r300InitSwtcl(GLcontext
*ctx
)
570 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
571 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
572 static int firsttime
= 1;
573 if (RADEON_DEBUG
& DEBUG_VERTS
)
574 fprintf(stderr
, "%s\n", __func__
);
580 rmesa
->radeon
.swtcl
.primitive_counter
= 0;
582 tnl
->Driver
.Render
.Start
= r300RenderStart
;
583 tnl
->Driver
.Render
.Finish
= r300RenderFinish
;
584 tnl
->Driver
.Render
.PrimitiveNotify
= r300RenderPrimitive
;
585 tnl
->Driver
.Render
.ResetLineStipple
= r300ResetLineStipple
;
586 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
587 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
588 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
590 /* FIXME: what are these numbers? */
591 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
592 48 * sizeof(GLfloat
) );
594 rmesa
->radeon
.swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
595 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
596 rmesa
->radeon
.swtcl
.render_primitive
= GL_TRIANGLES
;
597 rmesa
->radeon
.swtcl
.hw_primitive
= 0;
599 _tnl_invalidate_vertex_state( ctx
, ~0 );
600 _tnl_invalidate_vertices( ctx
, ~0 );
602 _tnl_need_projected_coords( ctx
, GL_FALSE
);
605 void r300DestroySwtcl(GLcontext
*ctx
)
609 static void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, struct radeon_bo
*bo
, GLuint offset
)
611 BATCH_LOCALS(&rmesa
->radeon
);
613 if (RADEON_DEBUG
& DEBUG_VERTS
)
614 fprintf(stderr
, "%s: vertex_size %d, offset 0x%x \n",
615 __FUNCTION__
, vertex_size
, offset
);
618 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR
, 2);
620 OUT_BATCH(vertex_size
| (vertex_size
<< 8));
621 OUT_BATCH_RELOC(offset
, bo
, offset
, RADEON_GEM_DOMAIN_GTT
, 0, 0);
625 static void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
)
627 BATCH_LOCALS(&rmesa
->radeon
);
629 if (RADEON_DEBUG
& DEBUG_VERTS
)
630 fprintf(stderr
, "%s\n", __func__
);
632 type
= r300PrimitiveType(rmesa
, primitive
);
633 num_verts
= r300NumVerts(rmesa
, vertex_nr
, primitive
);
636 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
637 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (num_verts
<< 16) | type
);
641 void r300_swtcl_flush(GLcontext
*ctx
, uint32_t current_offset
)
643 if (RADEON_DEBUG
& DEBUG_VERTS
)
644 fprintf(stderr
, "%s\n", __func__
);
645 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
647 radeonEmitState(&rmesa
->radeon
);
648 r300_emit_scissor(ctx
);
649 r300EmitVertexAOS(rmesa
,
650 rmesa
->radeon
.swtcl
.vertex_size
,
651 first_elem(&rmesa
->radeon
.dma
.reserved
)->bo
,
654 r300EmitVbufPrim(rmesa
,
655 rmesa
->radeon
.swtcl
.hw_primitive
,
656 rmesa
->radeon
.swtcl
.numverts
);
657 r300EmitCacheFlush(rmesa
);
658 rmesa
->radeon
.swtcl
.primitive_counter
= 0;