Change to use the t_vertex.c mechanisms for building vertices,
[mesa.git] / src / mesa / drivers / dri / unichrome / via_context.h
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #ifndef _VIACONTEXT_H
27 #define _VIACONTEXT_H
28
29 typedef struct via_context_t viaContext;
30 typedef struct via_context_t *viaContextPtr;
31 typedef struct via_texture_object_t *viaTextureObjectPtr;
32
33 #include "dri_util.h"
34
35 #include "mtypes.h"
36 #include "drm.h"
37 #include "mm.h"
38 #include "tnl/t_vertex.h"
39
40 #include "via_screen.h"
41 #include "via_tex.h"
42 #include "via_common.h"
43 #include "xf86drmVIA.h"
44
45 #define VIA_FALLBACK_TEXTURE 0x1
46 #define VIA_FALLBACK_DRAW_BUFFER 0x2
47 #define VIA_FALLBACK_READ_BUFFER 0x4
48 #define VIA_FALLBACK_COLORMASK 0x8
49 #define VIA_FALLBACK_SPECULAR 0x20
50 #define VIA_FALLBACK_LOGICOP 0x40
51 #define VIA_FALLBACK_RENDERMODE 0x80
52 #define VIA_FALLBACK_STENCIL 0x100
53 #define VIA_FALLBACK_BLEND_EQ 0x200
54 #define VIA_FALLBACK_BLEND_FUNC 0x400
55 #define VIA_FALLBACK_USER_DISABLE 0x800
56 #define VIA_FALLBACK_PROJ_TEXTURE 0x1000
57
58 #define VIA_DMA_BUFSIZ 4096
59 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
60
61 #define VIA_NO_CLIPRECTS 0x1
62
63
64 /* Use the templated vertex formats:
65 */
66 #define TAG(x) via##x
67 #include "tnl_dd/t_dd_vertex.h"
68 #undef TAG
69
70 typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
71 viaVertex *);
72 typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
73 typedef void (*via_point_func)(viaContextPtr, viaVertex *);
74
75 typedef struct {
76 drm_handle_t handle;
77 drmSize size;
78 GLuint offset;
79 GLuint index;
80 GLuint pitch;
81 GLuint bpp;
82 char *map;
83 GLuint orig; /* The drawing origin,
84 * at (drawX,drawY) in screen space.
85 */
86 char *origMap;
87 } viaBuffer, *viaBufferPtr;
88
89
90 struct via_context_t {
91 GLint refcount;
92 GLcontext *glCtx;
93 GLcontext *shareCtx;
94 viaBuffer front;
95 viaBuffer back;
96 viaBuffer depth;
97 GLboolean hasBack;
98 GLboolean hasDepth;
99 GLboolean hasStencil;
100 GLboolean hasAccum;
101 GLuint depthBits;
102 GLuint stencilBits;
103
104 GLboolean have_hw_stencil;
105 GLuint ClearDepth;
106 GLuint depth_clear_mask;
107 GLuint stencil_clear_mask;
108 GLfloat depth_max;
109 GLfloat polygon_offset_scale;
110
111 GLubyte *dma;
112 viaRegion tex;
113
114 GLuint isAGP;
115
116 /* Textures
117 */
118 viaTextureObjectPtr CurrentTexObj[2];
119 struct via_texture_object_t TexObjList;
120 struct via_texture_object_t SwappedOut;
121 memHeap_t *texHeap;
122
123 /* Bit flag to keep 0track of fallbacks.
124 */
125 GLuint Fallback;
126
127 /* State for via_tris.c.
128 */
129 GLuint newState; /* _NEW_* flags */
130 GLuint newEmitState; /* _NEW_* flags */
131 GLuint newRenderState; /* _NEW_* flags */
132
133 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
134 GLuint vertex_attr_count;
135
136 GLuint setupIndex;
137 GLuint renderIndex;
138 GLmatrix ViewportMatrix;
139 GLenum renderPrimitive;
140 GLenum hwPrimitive;
141 unsigned char *verts;
142
143 /* drmBufPtr dma_buffer;
144 */
145 GLuint dmaLow;
146 GLuint dmaCliprectAddr;
147 GLuint dmaLastPrim;
148 GLboolean useAgp;
149
150
151 /* Fallback rasterization functions
152 */
153 via_point_func drawPoint;
154 via_line_func drawLine;
155 via_tri_func drawTri;
156
157 /* Hardware register
158 */
159 GLuint regCmdA;
160 GLuint regCmdA_End;
161 GLuint regCmdB;
162
163 GLuint regEnable;
164 GLuint regHFBBMSKL;
165 GLuint regHROP;
166
167 GLuint regHZWTMD;
168 GLuint regHSTREF;
169 GLuint regHSTMD;
170
171 GLuint regHATMD;
172 GLuint regHABLCsat;
173 GLuint regHABLCop;
174 GLuint regHABLAsat;
175 GLuint regHABLAop;
176 GLuint regHABLRCa;
177 GLuint regHABLRFCa;
178 GLuint regHABLRCbias;
179 GLuint regHABLRCb;
180 GLuint regHABLRFCb;
181 GLuint regHABLRAa;
182 GLuint regHABLRAb;
183 GLuint regHFogLF;
184 GLuint regHFogCL;
185 GLuint regHFogCH;
186
187 GLuint regHLP;
188 GLuint regHLPRF;
189
190 GLuint regHTXnTB_0;
191 GLuint regHTXnMPMD_0;
192 GLuint regHTXnTBLCsat_0;
193 GLuint regHTXnTBLCop_0;
194 GLuint regHTXnTBLMPfog_0;
195 GLuint regHTXnTBLAsat_0;
196 GLuint regHTXnTBLRCb_0;
197 GLuint regHTXnTBLRAa_0;
198 GLuint regHTXnTBLRFog_0;
199 /*=* John Sheng [2003.7.18] texture combine *=*/
200 GLuint regHTXnTBLRCa_0;
201 GLuint regHTXnTBLRCc_0;
202 GLuint regHTXnTBLRCbias_0;
203
204 GLuint regHTXnTB_1;
205 GLuint regHTXnMPMD_1;
206 GLuint regHTXnTBLCsat_1;
207 GLuint regHTXnTBLCop_1;
208 GLuint regHTXnTBLMPfog_1;
209 GLuint regHTXnTBLAsat_1;
210 GLuint regHTXnTBLRCb_1;
211 GLuint regHTXnTBLRAa_1;
212 GLuint regHTXnTBLRFog_1;
213
214 int vertexSize;
215 int hwVertexSize;
216 GLboolean ptexHack;
217 int coloroffset;
218 int specoffset;
219
220 GLint lastStamp;
221
222 GLenum TexEnvImageFmt[2];
223 GLuint ClearColor;
224 GLuint ClearMask;
225
226 /* DRI stuff
227 */
228 GLuint needClip;
229 GLframebuffer *glBuffer;
230 GLboolean doPageFlip;
231 /*=* John Sheng [2003.5.31] flip *=*/
232 GLuint currentPage;
233
234 viaBuffer *drawBuffer;
235 viaBuffer *readBuffer;
236 int drawX; /* origin of drawable in draw buffer */
237 int drawY;
238
239 int drawW;
240 int drawH;
241
242 int drawXoff;
243 GLuint numClipRects; /* cliprects for that buffer */
244 drm_clip_rect_t *pClipRects;
245
246 int lastSwap;
247 int texAge;
248 int ctxAge;
249 int dirtyAge;
250
251 GLboolean scissor;
252 drm_clip_rect_t drawRect;
253 drm_clip_rect_t scissorRect;
254
255 drm_context_t hHWContext;
256 drm_hw_lock_t *driHwLock;
257 int driFd;
258 __DRInativeDisplay *display;
259
260 __DRIdrawablePrivate *driDrawable;
261 __DRIscreenPrivate *driScreen;
262 viaScreenPrivate *viaScreen;
263 drm_via_sarea_t *sarea;
264 volatile GLuint* regMMIOBase;
265 volatile GLuint* pnGEMode;
266 volatile GLuint* regEngineStatus;
267 volatile GLuint* regTranSet;
268 volatile GLuint* regTranSpace;
269 GLuint* agpBase;
270 GLuint drawType;
271
272 GLuint nDoneFirstFlip;
273 GLuint agpFullCount;
274
275 /* Configuration cache
276 */
277 driOptionCache optionCache;
278
279 GLuint vblank_flags;
280 GLuint vbl_seq;
281
282 int64_t swap_ust;
283 int64_t swap_missed_ust;
284
285 GLuint swap_count;
286 GLuint swap_missed_count;
287
288 PFNGLXGETUSTPROC get_ust;
289
290 };
291
292
293
294 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
295
296 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
297 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
298
299
300 /* Lock the hardware and validate our state.
301 */
302 #define LOCK_HARDWARE(vmesa) \
303 do { \
304 char __ret = 0; \
305 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
306 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
307 if (__ret) \
308 viaGetLock(vmesa, 0); \
309 } while (0)
310
311
312 /* Release the kernel lock.
313 */
314 #define UNLOCK_HARDWARE(vmesa) \
315 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
316
317 #define WAIT_IDLE(vmesa) \
318 do { \
319 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
320 break; \
321 } while (1)
322
323
324 #ifdef DEBUG
325 extern GLuint VIA_DEBUG;
326 #else
327 #define VIA_DEBUG 0
328 #endif
329
330
331 extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
332 extern void viaLock(viaContextPtr vmesa, GLuint flags);
333 extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
334 extern void viaEmitHwStateLocked(viaContextPtr vmesa);
335 extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
336 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
337 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
338 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
339 extern void viaXMesaWindowMoved(viaContextPtr vmesa);
340
341 extern void viaTexCombineState(viaContextPtr vmesa,
342 const struct gl_tex_env_combine_state * combine, unsigned unit );
343
344 /* Via hw already adjusted for GL pixel centers:
345 */
346 #define SUBPIXEL_X 0
347 #define SUBPIXEL_Y 0
348
349 /* TODO XXX _SOLO temp defines to make code compilable */
350 #ifndef GLX_PBUFFER_BIT
351 #define GLX_PBUFFER_BIT 0x00000004
352 #endif
353 #ifndef GLX_WINDOW_BIT
354 #define GLX_WINDOW_BIT 0x00000001
355 #endif
356 #ifndef VERT_BIT_CLIP
357 #define VERT_BIT_CLIP 0x1000000
358 #endif
359
360 #endif