(Stephane Marchesin, me) add hyperz support to radeon and r200 drivers. Only fast...
[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_ioctl.h"
49 #include "radeon_state.h"
50 #include "r300_context.h"
51 #include "r300_ioctl.h"
52 #include "r300_state.h"
53 #include "r300_reg.h"
54 #include "r300_program.h"
55
56
57 /**********************************************************************
58 * Hardware rasterization
59 *
60 * When we fell back to software TCL, we still try to use the
61 * rasterization hardware for rendering.
62 **********************************************************************/
63
64
65 /**
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.
70 */
71 static GLboolean r300_run_render(GLcontext *ctx,
72 struct tnl_pipeline_stage *stage)
73 {
74 if (RADEON_DEBUG == DEBUG_PRIMS)
75 fprintf(stderr, "%s\n", __FUNCTION__);
76
77 return GL_TRUE;
78
79 #if 0
80 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
81 TNLcontext *tnl = TNL_CONTEXT(ctx);
82 struct vertex_buffer *VB = &tnl->vb;
83 GLuint i;
84
85 /* Don't handle clipping or indexed vertices or vertex manipulations.
86 */
87 if (mmesa->RenderIndex != 0 ||
88 !mga_validate_render( ctx, VB )) {
89 return GL_TRUE;
90 }
91
92 tnl->Driver.Render.Start( ctx );
93 mmesa->SetupNewInputs = ~0;
94
95 for (i = 0 ; i < VB->PrimitiveCount ; i++)
96 {
97 GLuint prim = VB->Primitive[i].mode;
98 GLuint start = VB->Primitive[i].start;
99 GLuint length = VB->Primitive[i].count;
100
101 if (!length)
102 continue;
103
104 mga_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
105 prim);
106 }
107
108 tnl->Driver.Render.Finish( ctx );
109
110 return GL_FALSE; /* finished the pipe */
111 #endif
112 }
113
114
115 /**
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
120 */
121 #define FALLBACK_IF(expr) \
122 do { \
123 if (expr) { \
124 if (RADEON_DEBUG & DEBUG_FALLBACKS) \
125 fprintf(stderr, "%s: fallback:%s\n", \
126 __FUNCTION__, #expr); \
127 stage->active = GL_FALSE; \
128 return; \
129 } \
130 } while(0)
131
132 static void r300_check_render(GLcontext *ctx, struct tnl_pipeline_stage *stage)
133 {
134 r300ContextPtr r300 = R300_CONTEXT(ctx);
135 int i;
136
137 if (RADEON_DEBUG & DEBUG_STATE)
138 fprintf(stderr, "%s\n", __FUNCTION__);
139
140 /* We only support rendering in hardware for now */
141 if (ctx->RenderMode != GL_RENDER) {
142 stage->active = GL_FALSE;
143 return;
144 }
145
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);
149
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
166
167 for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
168 FALLBACK_IF(ctx->Texture.Unit[i].Enabled);
169
170 stage->active = GL_FALSE;
171 }
172
173
174 static void dtr(struct tnl_pipeline_stage *stage)
175 {
176 (void)stage;
177 }
178
179 const struct tnl_pipeline_stage _r300_render_stage = {
180 "r300 hw rasterize",
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 */
189 };