1 /* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_context.h,v 1.2 2002/02/22 21:32:58 dawes Exp $ */
11 #include "ffb_xmesa.h"
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)
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
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)
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
*,
55 typedef void (*ffb_quad_func
)(GLcontext
*, ffb_vertex
*, ffb_vertex
*,
56 ffb_vertex
*, ffb_vertex
*);
58 /* Immediate mode fast-path support. */
67 } ffbTnlVertex
, *ffbTnlVertexPtr
;
69 typedef void (*ffb_interp_func
)(GLfloat t
,
71 const ffbTnlVertex
*I
,
72 const ffbTnlVertex
*J
);
74 struct ffb_current_state
{
80 struct ffb_light_state
{
81 GLfloat base_color
[3];
85 struct ffb_vertex_state
{
86 struct ffb_current_state current
;
87 struct ffb_light_state light
;
90 struct ffb_imm_vertex
{
91 ffbTnlVertex vertices
[8];
97 void (*save_vertex
)(GLcontext
*ctx
, ffbTnlVertex
*v
);
98 void (*flush_vertex
)(GLcontext
*ctx
, ffbTnlVertex
*v
);
100 ffb_interp_func interp
;
104 GLvertexformat vtxfmt
;
107 typedef struct ffb_context_t
{
109 GLframebuffer
*glBuffer
;
112 volatile char *sfb32
;
116 int back_buffer
; /* 0 = bufferA, 1 = bufferB */
118 /* Viewport matrix. */
119 GLfloat hw_viewport
[16];
120 #define SUBPIXEL_X (-0.5F)
121 #define SUBPIXEL_Y (-0.5F + 0.125)
123 /* Vertices in driver format. */
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
;
132 GLenum raster_primitive
;
133 GLenum render_primitive
;
135 GLfloat backface_sign
;
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
;
145 /* Immediate mode state. */
146 struct ffb_vertex_state vtx_state
;
147 struct ffb_imm_vertex imm
;
149 /* Debugging knobs. */
150 GLboolean debugFallbacks
;
152 /* This records state bits when a per-fragment attribute has
153 * been set which prevents us from rendering in hardware.
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.
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 */
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
193 unsigned int state_all_fifo_ents
;
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; \
202 /* General hw reg state. */
209 #define FFB_LPAT_BAD 0xffffffff
218 unsigned int matchab
;
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 */
239 /* Blend unit hw reg state. */
241 unsigned int blendc1
;
242 unsigned int blendc2
;
244 /* ViewPort clipping hw reg state. */
245 unsigned int vclipmin
;
246 unsigned int vclipmax
;
247 unsigned int vclipzmin
;
248 unsigned int vclipzmax
;
254 /* Stencil control hw reg state. >=FFB2+ only. */
255 unsigned int stencil
;
256 unsigned int stencilctl
;
257 unsigned int consty
; /* Stencil Ref */
259 /* Area pattern (used for polygon stipples). */
260 unsigned int pattern
[32];
265 drm_context_t hHWContext
;
266 drm_hw_lock_t
*driHwLock
;
269 unsigned int clear_pixel
;
270 unsigned int clear_depth
;
271 unsigned int clear_stencil
;
273 unsigned int setupindex
;
274 unsigned int setupnewinputs
;
275 unsigned int new_gl_state
;
277 __DRIdrawablePrivate
*driDrawable
;
278 __DRIscreenPrivate
*driScreen
;
279 ffbScreenPrivate
*ffbScreen
;
280 ffb_dri_state_t
*ffb_sarea
;
281 } ffbContextRec
, *ffbContextPtr
;
283 #define FFB_CONTEXT(ctx) ((ffbContextPtr)((ctx)->DriverCtx))
285 /* We want the depth values written during software rendering
286 * to match what the hardware is going to put there when we
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
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.
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).
303 #define Z_TO_MESA(VAL) ((GLuint)(((VAL) & 0x0fffffff) << (32 - 28)))
304 #define Z_FROM_MESA(VAL) (((GLuint)((GLdouble)(VAL))) >> (32 - 28))
306 #endif /* !(_FFB_CONTEXT_H) */