1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/**************************************************************************
Copyright (C) 2004 Nicolai Haehnle.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Nicolai Haehnle <prefect_@gmx.net>
*/
#include "glheader.h"
#include "state.h"
#include "imports.h"
#include "enums.h"
#include "macros.h"
#include "context.h"
#include "dd.h"
#include "simple_list.h"
#include "api_arrayelt.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "array_cache/acache.h"
#include "tnl/tnl.h"
#include "radeon_ioctl.h"
#include "radeon_state.h"
#include "r300_context.h"
#include "r300_ioctl.h"
#include "r300_state.h"
#include "r300_reg.h"
#include "r300_program.h"
#include "r300_lib.h"
/**********************************************************************
* Hardware rasterization
*
* When we fell back to software TCL, we still try to use the
* rasterization hardware for rendering.
**********************************************************************/
static void r300_render_primitive(r300ContextPtr rmesa,
GLcontext *ctx,
int start,
int end,
int prim)
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
GLuint i;
int k;
ADAPTOR adaptor;
LOCAL_VARS
if(end<=start)return; /* do we need to watch for this ? */
adaptor=TWO_PIPE_ADAPTOR;
adaptor.color_offset[0]=rmesa->radeon.radeonScreen->backOffset+rmesa->radeon.radeonScreen->fbLocation;
adaptor.color_pitch[0]=(rmesa->radeon.radeonScreen->backPitch) | (0xc0<<16);
adaptor.depth_offset=rmesa->radeon.radeonScreen->depthOffset;
adaptor.depth_pitch=rmesa->radeon.radeonScreen->depthPitch | (0x2 << 16);
init_3d(PASS_PREFIX &adaptor);
init_flat_primitive(PASS_PREFIX &adaptor);
set_scissors(PASS_PREFIX 0, 0, 2647, 1941);
set_cliprect(PASS_PREFIX 0, 0, 0, 2647,1941);
set_cliprect(PASS_PREFIX 1, 0, 0, 2647,1941);
set_cliprect(PASS_PREFIX 2, 0, 0, 2647,1941);
set_cliprect(PASS_PREFIX 3, 0, 0, 2647,1941);
reg_start(R300_RE_OCCLUSION_CNTL, 0);
e32(R300_OCCLUSION_ON);
set_quad0(PASS_PREFIX 1.0,1.0,1.0,1.0);
set_init21(PASS_PREFIX 0.0,1.0);
fprintf(stderr, "[%d-%d]", start, end);
switch (prim & PRIM_MODE_MASK) {
case GL_LINES:
fprintf(stderr, "L ");
break;
case GL_LINE_STRIP:
fprintf(stderr, "LS ");
break;
case GL_LINE_LOOP:
fprintf(stderr, "LL ");
break;
case GL_TRIANGLES:
fprintf(stderr, "T ");
break;
case GL_TRIANGLE_STRIP:
fprintf(stderr, "TS ");
break;
case GL_TRIANGLE_FAN:
fprintf(stderr, "TF ");
break;
case GL_QUADS:
fprintf(stderr, "Q ");
for(i=start+3;i<end;i+=4){
start_primitive(PASS_PREFIX R300_VAP_VF_CNTL__PRIM_QUADS);
for(k=-3;k<=0;k++){
#if 1
fprintf(stderr, "* (%f %f %f) (%f %f %f)\n",
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[0],
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[1],
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[2],
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[0],
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[1],
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[2]
);
#endif
emit_flat_vertex(PASS_PREFIX
/* coordinates */
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[0],
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[1],
VEC_ELT(VB->ObjPtr, GLfloat, i+k)[2],
/* colors */
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[0],
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[1],
VEC_ELT(VB->ColorPtr[0], GLfloat, i+k)[2]
);
}
end_primitive(PASS_PREFIX_VOID);
}
break;
case GL_QUAD_STRIP:
fprintf(stderr, "QS ");
break;
default:
fprintf(stderr, "%02x ", VB->Primitive[i].mode & PRIM_MODE_MASK);
break;
}
end_3d(PASS_PREFIX_VOID);
}
/**
* Called by the pipeline manager to render a batch of primitives.
* We can return true to pass on to the next stage (i.e. software
* rasterization) or false to indicate that the pipeline has finished
* after we render something.
*/
static GLboolean r300_run_render(GLcontext *ctx,
struct tnl_pipeline_stage *stage)
{
r300ContextPtr rmesa = R300_CONTEXT(ctx);
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
GLuint i;
if (RADEON_DEBUG == DEBUG_PRIMS)
fprintf(stderr, "%s\n", __FUNCTION__);
for(i=0; i < VB->PrimitiveCount; i++){
GLuint prim = VB->Primitive[i].mode;
GLuint start = VB->Primitive[i].start;
GLuint length = VB->Primitive[i].count;
r300_render_primitive(rmesa, ctx, start, start + length, prim);
}
fprintf(stderr, "\n");
#if 0
return GL_TRUE;
#else
return GL_FALSE;
#endif
#if 0
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
GLuint i;
/* Don't handle clipping or indexed vertices or vertex manipulations.
*/
if (mmesa->RenderIndex != 0 ||
!mga_validate_render( ctx, VB )) {
return GL_TRUE;
}
tnl->Driver.Render.Start( ctx );
mmesa->SetupNewInputs = ~0;
for (i = 0 ; i < VB->PrimitiveCount ; i++)
{
GLuint prim = VB->Primitive[i].mode;
GLuint start = VB->Primitive[i].start;
GLuint length = VB->Primitive[i].count;
if (!length)
continue;
mga_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
prim);
}
tnl->Driver.Render.Finish( ctx );
return GL_FALSE; /* finished the pipe */
#endif
}
/**
* Called by the pipeline manager once before rendering.
* We check the GL state here to
* a) decide whether we can do the current state in hardware and
* b) update hardware registers
*/
#define FALLBACK_IF(expr) \
do { \
if (expr) { \
if (RADEON_DEBUG & DEBUG_FALLBACKS) \
fprintf(stderr, "%s: fallback:%s\n", \
__FUNCTION__, #expr); \
stage->active = GL_FALSE; \
return; \
} \
} while(0)
static void r300_check_render(GLcontext *ctx, struct tnl_pipeline_stage *stage)
{
r300ContextPtr r300 = R300_CONTEXT(ctx);
int i;
if (RADEON_DEBUG & DEBUG_STATE)
fprintf(stderr, "%s\n", __FUNCTION__);
/* We only support rendering in hardware for now */
if (ctx->RenderMode != GL_RENDER) {
stage->active = GL_FALSE;
return;
}
// I failed to figure out how dither works in hardware,
// let's just ignore it for now
//FALLBACK_IF(ctx->Color.DitherFlag);
/* I'm almost certain I forgot something here */
FALLBACK_IF(ctx->Color.AlphaEnabled); // GL_ALPHA_TEST
FALLBACK_IF(ctx->Color.BlendEnabled); // GL_BLEND
FALLBACK_IF(ctx->Fog.Enabled); // GL_FOG
FALLBACK_IF(ctx->Line.SmoothFlag); // GL_LINE_SMOOTH
FALLBACK_IF(ctx->Line.StippleFlag); // GL_LINE_STIPPLE
FALLBACK_IF(ctx->Point.SmoothFlag); // GL_POINT_SMOOTH
if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite)
FALLBACK_IF(ctx->Point.PointSprite); // GL_POINT_SPRITE_NV
FALLBACK_IF(ctx->Polygon.OffsetPoint); // GL_POLYGON_OFFSET_POINT
FALLBACK_IF(ctx->Polygon.OffsetLine); // GL_POLYGON_OFFSET_LINE
FALLBACK_IF(ctx->Polygon.OffsetFill); // GL_POLYGON_OFFSET_FILL
FALLBACK_IF(ctx->Polygon.SmoothFlag); // GL_POLYGON_SMOOTH
FALLBACK_IF(ctx->Polygon.StippleFlag); // GL_POLYGON_STIPPLE
FALLBACK_IF(ctx->Stencil.Enabled); // GL_STENCIL_TEST
FALLBACK_IF(ctx->Multisample.Enabled); // GL_MULTISAMPLE_ARB
for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
FALLBACK_IF(ctx->Texture.Unit[i].Enabled);
/* let r300_run_render do its job */
#if 0
stage->active = GL_FALSE;
#endif
}
static void dtr(struct tnl_pipeline_stage *stage)
{
(void)stage;
}
const struct tnl_pipeline_stage _r300_render_stage = {
"r300 hw rasterize",
_NEW_ALL, /* re-check (always re-check for now) */
0, /* re-run (always runs) */
GL_TRUE, /* active */
0, 0, /* inputs (set in check_render), outputs */
0, 0, /* changed_inputs, private */
dtr, /* destructor */
r300_check_render, /* check */
r300_run_render /* run */
};
|