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