df1b65d748f5f9b9ed12b5941f31b9b52e1f0bc0
[mesa.git] / src / mesa / drivers / dri / ffb / ffb_context.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_context.h,v 1.2 2002/02/22 21:32:58 dawes Exp $ */
2
3 #ifndef _FFB_CONTEXT_H
4 #define _FFB_CONTEXT_H
5
6 #include "dri_util.h"
7 #include "drm.h"
8
9 #include "mtypes.h"
10
11 #include "ffb_xmesa.h"
12
13 typedef struct {
14 GLfloat alpha;
15 GLfloat red;
16 GLfloat green;
17 GLfloat blue;
18 } ffb_color;
19
20 #define FFB_GET_ALPHA(VTX) \
21 FFB_COLOR_FROM_FLOAT((VTX)->color[0].alpha)
22 #define FFB_GET_RED(VTX) \
23 FFB_COLOR_FROM_FLOAT((VTX)->color[0].red)
24 #define FFB_GET_GREEN(VTX) \
25 FFB_COLOR_FROM_FLOAT((VTX)->color[0].green)
26 #define FFB_GET_BLUE(VTX) \
27 FFB_COLOR_FROM_FLOAT((VTX)->color[0].blue)
28
29 typedef struct {
30 GLfloat x, y, z;
31 ffb_color color[2];
32 } ffb_vertex;
33
34 #define FFB_DELAYED_VIEWPORT_VARS \
35 GLfloat VP_SX = fmesa->hw_viewport[MAT_SX]; \
36 GLfloat VP_TX = fmesa->hw_viewport[MAT_TX]; \
37 GLfloat VP_SY = fmesa->hw_viewport[MAT_SY]; \
38 GLfloat VP_TY = fmesa->hw_viewport[MAT_TY]; \
39 GLfloat VP_SZ = fmesa->hw_viewport[MAT_SZ]; \
40 GLfloat VP_TZ = fmesa->hw_viewport[MAT_TZ]; \
41 (void) VP_SX; (void) VP_SY; (void) VP_SZ; \
42 (void) VP_TX; (void) VP_TY; (void) VP_TZ
43
44 #define FFB_GET_Z(VTX) \
45 FFB_Z_FROM_FLOAT(VP_SZ * (VTX)->z + VP_TZ)
46 #define FFB_GET_Y(VTX) \
47 FFB_XY_FROM_FLOAT(VP_SY * (VTX)->y + VP_TY)
48 #define FFB_GET_X(VTX) \
49 FFB_XY_FROM_FLOAT(VP_SX * (VTX)->x + VP_TX)
50
51 typedef void (*ffb_point_func)(GLcontext *, ffb_vertex *);
52 typedef void (*ffb_line_func)(GLcontext *, ffb_vertex *, ffb_vertex *);
53 typedef void (*ffb_tri_func)(GLcontext *, ffb_vertex *, ffb_vertex *,
54 ffb_vertex *);
55 typedef void (*ffb_quad_func)(GLcontext *, ffb_vertex *, ffb_vertex *,
56 ffb_vertex *, ffb_vertex *);
57
58 /* Immediate mode fast-path support. */
59 typedef struct {
60 GLfloat obj[4];
61 GLfloat normal[4];
62 GLfloat clip[4];
63 GLuint mask;
64 GLfloat color[4];
65 GLfloat win[4];
66 GLfloat eye[4];
67 } ffbTnlVertex, *ffbTnlVertexPtr;
68
69 typedef void (*ffb_interp_func)(GLfloat t,
70 ffbTnlVertex *O,
71 const ffbTnlVertex *I,
72 const ffbTnlVertex *J);
73
74 struct ffb_current_state {
75 GLfloat color[4];
76 GLfloat normal[4];
77 GLfloat specular[4];
78 };
79
80 struct ffb_light_state {
81 GLfloat base_color[3];
82 GLfloat base_alpha;
83 };
84
85 struct ffb_vertex_state {
86 struct ffb_current_state current;
87 struct ffb_light_state light;
88 };
89
90 struct ffb_imm_vertex {
91 ffbTnlVertex vertices[8];
92 ffbTnlVertex *v0;
93 ffbTnlVertex *v1;
94 ffbTnlVertex *v2;
95 ffbTnlVertex *v3;
96
97 void (*save_vertex)(GLcontext *ctx, ffbTnlVertex *v);
98 void (*flush_vertex)(GLcontext *ctx, ffbTnlVertex *v);
99
100 ffb_interp_func interp;
101
102 GLuint prim, format;
103
104 GLvertexformat vtxfmt;
105 };
106
107 typedef struct ffb_context_t {
108 GLcontext *glCtx;
109 GLframebuffer *glBuffer;
110
111 ffb_fbcPtr regs;
112 volatile char *sfb32;
113
114 int hw_locked;
115
116 int back_buffer; /* 0 = bufferA, 1 = bufferB */
117
118 /* Viewport matrix. */
119 GLfloat hw_viewport[16];
120 #define SUBPIXEL_X (-0.5F)
121 #define SUBPIXEL_Y (-0.5F + 0.125)
122
123 /* Vertices in driver format. */
124 ffb_vertex *verts;
125
126 /* Rasterization functions. */
127 ffb_point_func draw_point;
128 ffb_line_func draw_line;
129 ffb_tri_func draw_tri;
130 ffb_quad_func draw_quad;
131
132 GLenum raster_primitive;
133 GLenum render_primitive;
134
135 GLfloat backface_sign;
136 GLfloat depth_scale;
137
138 GLfloat ffb_2_30_fixed_scale;
139 GLfloat ffb_one_over_2_30_fixed_scale;
140 GLfloat ffb_16_16_fixed_scale;
141 GLfloat ffb_one_over_16_16_fixed_scale;
142 GLfloat ffb_ubyte_color_scale;
143 GLfloat ffb_zero;
144
145 /* Immediate mode state. */
146 struct ffb_vertex_state vtx_state;
147 struct ffb_imm_vertex imm;
148
149 /* Debugging knobs. */
150 GLboolean debugFallbacks;
151
152 /* This records state bits when a per-fragment attribute has
153 * been set which prevents us from rendering in hardware.
154 *
155 * As attributes change, some of these bits may clear as
156 * we move back within the chips capabilities. If they
157 * all clear, we return to full hw rendering.
158 */
159 unsigned int bad_fragment_attrs;
160 #define FFB_BADATTR_FOG 0x00000001 /* Bad fog possible only when < FFB2 */
161 #define FFB_BADATTR_BLENDFUNC 0x00000002 /* Any non-const func based upon dst alpha */
162 #define FFB_BADATTR_BLENDROP 0x00000004 /* Blend enabled and LogicOP != GL_COPY */
163 #define FFB_BADATTR_BLENDEQN 0x00000008 /* Blend equation other than ADD */
164 #define FFB_BADATTR_STENCIL 0x00000010 /* Stencil enabled when < FFB2+ */
165 #define FFB_BADATTR_TEXTURE 0x00000020 /* Texture enabled */
166 #define FFB_BADATTR_SWONLY 0x00000040 /* Environment var set */
167
168 unsigned int state_dirty;
169 unsigned int state_fifo_ents;
170 #define FFB_STATE_FBC 0x00000001
171 #define FFB_STATE_PPC 0x00000002
172 #define FFB_STATE_DRAWOP 0x00000004
173 #define FFB_STATE_ROP 0x00000008
174 #define FFB_STATE_LPAT 0x00000010
175 #define FFB_STATE_PMASK 0x00000020
176 #define FFB_STATE_XPMASK 0x00000040
177 #define FFB_STATE_YPMASK 0x00000080
178 #define FFB_STATE_ZPMASK 0x00000100
179 #define FFB_STATE_XCLIP 0x00000200
180 #define FFB_STATE_CMP 0x00000400
181 #define FFB_STATE_MATCHAB 0x00000800
182 #define FFB_STATE_MAGNAB 0x00001000
183 #define FFB_STATE_MATCHC 0x00002000
184 #define FFB_STATE_MAGNC 0x00004000
185 #define FFB_STATE_DCUE 0x00008000
186 #define FFB_STATE_BLEND 0x00010000
187 #define FFB_STATE_CLIP 0x00020000
188 #define FFB_STATE_STENCIL 0x00040000
189 #define FFB_STATE_APAT 0x00080000
190 #define FFB_STATE_WID 0x00100000
191 #define FFB_STATE_ALL 0x001fffff
192
193 unsigned int state_all_fifo_ents;
194
195 #define FFB_MAKE_DIRTY(FMESA, STATE_MASK, FIFO_ENTS) \
196 do { if ((STATE_MASK) & ~((FMESA)->state_dirty)) { \
197 (FMESA)->state_dirty |= (STATE_MASK); \
198 (FMESA)->state_fifo_ents += FIFO_ENTS; \
199 } \
200 } while (0)
201
202 /* General hw reg state. */
203 unsigned int fbc;
204 unsigned int ppc;
205 unsigned int drawop;
206 unsigned int rop;
207
208 unsigned int lpat;
209 #define FFB_LPAT_BAD 0xffffffff
210
211 unsigned int wid;
212 unsigned int pmask;
213 unsigned int xpmask;
214 unsigned int ypmask;
215 unsigned int zpmask;
216 unsigned int xclip;
217 unsigned int cmp;
218 unsigned int matchab;
219 unsigned int magnab;
220 unsigned int matchc;
221 unsigned int magnc;
222
223 /* Depth cue unit hw reg state. */
224 unsigned int dcss; /* All FFB */
225 unsigned int dcsf; /* All FFB */
226 unsigned int dcsb; /* All FFB */
227 unsigned int dczf; /* All FFB */
228 unsigned int dczb; /* All FFB */
229 unsigned int dcss1; /* >=FFB2 only */
230 unsigned int dcss2; /* >=FFB2 only */
231 unsigned int dcss3; /* >=FFB2 only */
232 unsigned int dcs2; /* >=FFB2 only */
233 unsigned int dcs3; /* >=FFB2 only */
234 unsigned int dcs4; /* >=FFB2 only */
235 unsigned int dcd2; /* >=FFB2 only */
236 unsigned int dcd3; /* >=FFB2 only */
237 unsigned int dcd4; /* >=FFB2 only */
238
239 /* Blend unit hw reg state. */
240 unsigned int blendc;
241 unsigned int blendc1;
242 unsigned int blendc2;
243
244 /* ViewPort clipping hw reg state. */
245 unsigned int vclipmin;
246 unsigned int vclipmax;
247 unsigned int vclipzmin;
248 unsigned int vclipzmax;
249 struct {
250 unsigned int min;
251 unsigned int max;
252 } aux_clips[4];
253
254 /* Stencil control hw reg state. >=FFB2+ only. */
255 unsigned int stencil;
256 unsigned int stencilctl;
257 unsigned int consty; /* Stencil Ref */
258
259 /* Area pattern (used for polygon stipples). */
260 unsigned int pattern[32];
261
262 /* Fog state. */
263 float Znear, Zfar;
264
265 drm_context_t hHWContext;
266 drm_hw_lock_t *driHwLock;
267 int driFd;
268
269 unsigned int clear_pixel;
270 unsigned int clear_depth;
271 unsigned int clear_stencil;
272
273 unsigned int setupindex;
274 unsigned int setupnewinputs;
275 unsigned int new_gl_state;
276
277 __DRIdrawablePrivate *driDrawable;
278 __DRIscreenPrivate *driScreen;
279 ffbScreenPrivate *ffbScreen;
280 ffb_dri_state_t *ffb_sarea;
281 } ffbContextRec, *ffbContextPtr;
282
283 #define FFB_CONTEXT(ctx) ((ffbContextPtr)((ctx)->DriverCtx))
284
285 /* We want the depth values written during software rendering
286 * to match what the hardware is going to put there when we
287 * hw render.
288 *
289 * The Z buffer is 28 bits deep. Smooth shaded primitives
290 * specify a 2:30 signed fixed point Z value in the range 0.0
291 * to 1.0 inclusive.
292 *
293 * So for example, when hw rendering, the largest Z value of
294 * 1.0 would produce a value of 0x0fffffff in the actual Z
295 * buffer, which is the maximum value.
296 *
297 * Mesa's depth type is a 32-bit uint, so we use the following macro
298 * to convert to/from FFB hw Z values. Note we also have to clear
299 * out the top bits as that is where the Y (stencil) buffer is stored
300 * and during hw Z buffer reads it is always there. (During writes
301 * we tell the hw to discard those top 4 bits).
302 */
303 #define Z_TO_MESA(VAL) ((GLuint)(((VAL) & 0x0fffffff) << (32 - 28)))
304 #define Z_FROM_MESA(VAL) (((GLuint)((GLdouble)(VAL))) >> (32 - 28))
305
306 #endif /* !(_FFB_CONTEXT_H) */