8 #include "main/mtypes.h"
10 #include "ffb_xmesa.h"
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)
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
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)
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
*,
54 typedef void (*ffb_quad_func
)(GLcontext
*, ffb_vertex
*, ffb_vertex
*,
55 ffb_vertex
*, ffb_vertex
*);
57 /* Immediate mode fast-path support. */
66 } ffbTnlVertex
, *ffbTnlVertexPtr
;
68 typedef void (*ffb_interp_func
)(GLfloat t
,
70 const ffbTnlVertex
*I
,
71 const ffbTnlVertex
*J
);
73 struct ffb_current_state
{
79 struct ffb_light_state
{
80 GLfloat base_color
[3];
84 struct ffb_vertex_state
{
85 struct ffb_current_state current
;
86 struct ffb_light_state light
;
89 struct ffb_imm_vertex
{
90 ffbTnlVertex vertices
[8];
96 void (*save_vertex
)(GLcontext
*ctx
, ffbTnlVertex
*v
);
97 void (*flush_vertex
)(GLcontext
*ctx
, ffbTnlVertex
*v
);
99 ffb_interp_func interp
;
103 GLvertexformat vtxfmt
;
106 typedef struct ffb_context_t
{
108 GLframebuffer
*glBuffer
;
111 volatile char *sfb32
;
115 int back_buffer
; /* 0 = bufferA, 1 = bufferB */
117 /* Viewport matrix. */
118 GLfloat hw_viewport
[16];
119 #define SUBPIXEL_X (-0.5F)
120 #define SUBPIXEL_Y (-0.5F + 0.125)
122 /* Vertices in driver format. */
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
;
131 GLenum raster_primitive
;
132 GLenum render_primitive
;
134 GLfloat backface_sign
;
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
;
144 /* Immediate mode state. */
145 struct ffb_vertex_state vtx_state
;
146 struct ffb_imm_vertex imm
;
148 /* Debugging knobs. */
149 GLboolean debugFallbacks
;
151 /* This records state bits when a per-fragment attribute has
152 * been set which prevents us from rendering in hardware.
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.
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 */
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
192 unsigned int state_all_fifo_ents
;
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; \
201 /* General hw reg state. */
208 #define FFB_LPAT_BAD 0xffffffff
217 unsigned int matchab
;
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 */
238 /* Blend unit hw reg state. */
240 unsigned int blendc1
;
241 unsigned int blendc2
;
243 /* ViewPort clipping hw reg state. */
244 unsigned int vclipmin
;
245 unsigned int vclipmax
;
246 unsigned int vclipzmin
;
247 unsigned int vclipzmax
;
253 /* Stencil control hw reg state. >=FFB2+ only. */
254 unsigned int stencil
;
255 unsigned int stencilctl
;
256 unsigned int consty
; /* Stencil Ref */
258 /* Area pattern (used for polygon stipples). */
259 unsigned int pattern
[32];
264 drm_context_t hHWContext
;
265 drm_hw_lock_t
*driHwLock
;
268 unsigned int clear_pixel
;
269 unsigned int clear_depth
;
270 unsigned int clear_stencil
;
272 unsigned int setupindex
;
273 unsigned int setupnewinputs
;
274 unsigned int new_gl_state
;
276 __DRIdrawablePrivate
*driDrawable
;
277 __DRIscreenPrivate
*driScreen
;
278 ffbScreenPrivate
*ffbScreen
;
279 ffb_dri_state_t
*ffb_sarea
;
280 } ffbContextRec
, *ffbContextPtr
;
282 #define FFB_CONTEXT(ctx) ((ffbContextPtr)((ctx)->DriverCtx))
284 /* We want the depth values written during software rendering
285 * to match what the hardware is going to put there when we
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
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.
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).
302 #define Z_TO_MESA(VAL) ((GLuint)(((VAL) & 0x0fffffff) << (32 - 28)))
303 #define Z_FROM_MESA(VAL) (((GLuint)((GLdouble)(VAL))) >> (32 - 28))
305 #endif /* !(_FFB_CONTEXT_H) */