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"
48 #include "radeon_ioctl.h"
49 #include "radeon_state.h"
50 #include "r300_context.h"
51 #include "r300_ioctl.h"
52 #include "r300_state.h"
54 #include "r300_program.h"
57 /**********************************************************************
58 * Hardware rasterization
60 * When we fell back to software TCL, we still try to use the
61 * rasterization hardware for rendering.
62 **********************************************************************/
66 * Called by the pipeline manager to render a batch of primitives.
67 * We can return true to pass on to the next stage (i.e. software
68 * rasterization) or false to indicate that the pipeline has finished
69 * after we render something.
71 static GLboolean
r300_run_render(GLcontext
*ctx
,
72 struct tnl_pipeline_stage
*stage
)
74 if (RADEON_DEBUG
== DEBUG_PRIMS
)
75 fprintf(stderr
, "%s\n", __FUNCTION__
);
80 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
81 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
82 struct vertex_buffer
*VB
= &tnl
->vb
;
85 /* Don't handle clipping or indexed vertices or vertex manipulations.
87 if (mmesa
->RenderIndex
!= 0 ||
88 !mga_validate_render( ctx
, VB
)) {
92 tnl
->Driver
.Render
.Start( ctx
);
93 mmesa
->SetupNewInputs
= ~0;
95 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
97 GLuint prim
= VB
->Primitive
[i
].mode
;
98 GLuint start
= VB
->Primitive
[i
].start
;
99 GLuint length
= VB
->Primitive
[i
].count
;
104 mga_render_tab_verts
[prim
& PRIM_MODE_MASK
]( ctx
, start
, start
+ length
,
108 tnl
->Driver
.Render
.Finish( ctx
);
110 return GL_FALSE
; /* finished the pipe */
116 * Called by the pipeline manager once before rendering.
117 * We check the GL state here to
118 * a) decide whether we can do the current state in hardware and
119 * b) update hardware registers
121 #define FALLBACK_IF(expr) \
124 if (RADEON_DEBUG & DEBUG_FALLBACKS) \
125 fprintf(stderr, "%s: fallback:%s\n", \
126 __FUNCTION__, #expr); \
127 stage->active = GL_FALSE; \
132 static void r300_check_render(GLcontext
*ctx
, struct tnl_pipeline_stage
*stage
)
134 r300ContextPtr r300
= R300_CONTEXT(ctx
);
137 if (RADEON_DEBUG
& DEBUG_STATE
)
138 fprintf(stderr
, "%s\n", __FUNCTION__
);
140 /* We only support rendering in hardware for now */
141 if (ctx
->RenderMode
!= GL_RENDER
) {
142 stage
->active
= GL_FALSE
;
146 // I failed to figure out how dither works in hardware,
147 // let's just ignore it for now
148 //FALLBACK_IF(ctx->Color.DitherFlag);
150 /* I'm almost certain I forgot something here */
151 FALLBACK_IF(ctx
->Color
.AlphaEnabled
); // GL_ALPHA_TEST
152 FALLBACK_IF(ctx
->Color
.BlendEnabled
); // GL_BLEND
153 FALLBACK_IF(ctx
->Fog
.Enabled
); // GL_FOG
154 FALLBACK_IF(ctx
->Line
.SmoothFlag
); // GL_LINE_SMOOTH
155 FALLBACK_IF(ctx
->Line
.StippleFlag
); // GL_LINE_STIPPLE
156 FALLBACK_IF(ctx
->Point
.SmoothFlag
); // GL_POINT_SMOOTH
157 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
)
158 FALLBACK_IF(ctx
->Point
.PointSprite
); // GL_POINT_SPRITE_NV
159 FALLBACK_IF(ctx
->Polygon
.OffsetPoint
); // GL_POLYGON_OFFSET_POINT
160 FALLBACK_IF(ctx
->Polygon
.OffsetLine
); // GL_POLYGON_OFFSET_LINE
161 FALLBACK_IF(ctx
->Polygon
.OffsetFill
); // GL_POLYGON_OFFSET_FILL
162 FALLBACK_IF(ctx
->Polygon
.SmoothFlag
); // GL_POLYGON_SMOOTH
163 FALLBACK_IF(ctx
->Polygon
.StippleFlag
); // GL_POLYGON_STIPPLE
164 FALLBACK_IF(ctx
->Stencil
.Enabled
); // GL_STENCIL_TEST
165 FALLBACK_IF(ctx
->Multisample
.Enabled
); // GL_MULTISAMPLE_ARB
167 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
168 FALLBACK_IF(ctx
->Texture
.Unit
[i
].Enabled
);
170 stage
->active
= GL_FALSE
;
174 static void dtr(struct tnl_pipeline_stage
*stage
)
179 const struct tnl_pipeline_stage _r300_render_stage
= {
181 _NEW_ALL
, /* re-check (always re-check for now) */
182 0, /* re-run (always runs) */
183 GL_TRUE
, /* active */
184 0, 0, /* inputs (set in check_render), outputs */
185 0, 0, /* changed_inputs, private */
186 dtr
, /* destructor */
187 r300_check_render
, /* check */
188 r300_run_render
/* run */