summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/i810/i810context.h
blob: 47080420595396b5cf311f25186394a4a1ccc470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * GLX Hardware Device Driver for Intel i810
 * Copyright (C) 1999 Keith Whitwell
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef I810CONTEXT_INC
#define I810CONTEXT_INC

typedef struct i810_context_t i810Context;
typedef struct i810_context_t *i810ContextPtr;
typedef struct i810_texture_object_t *i810TextureObjectPtr;

#include "drm.h"
#include "mtypes.h"
#include "mm.h"

#include "i810screen.h"
#include "i810tex.h"


/* Reasons to disable hardware rasterization. 
 */
#define I810_FALLBACK_TEXTURE        0x1
#define I810_FALLBACK_DRAW_BUFFER    0x2
#define I810_FALLBACK_READ_BUFFER    0x4
#define I810_FALLBACK_COLORMASK      0x8  
#define I810_FALLBACK_SPECULAR       0x20 
#define I810_FALLBACK_LOGICOP        0x40
#define I810_FALLBACK_RENDERMODE     0x80
#define I810_FALLBACK_STENCIL        0x100
#define I810_FALLBACK_BLEND_EQ       0x200
#define I810_FALLBACK_BLEND_FUNC     0x400


#ifndef PCI_CHIP_I810				 
#define PCI_CHIP_I810              0x7121
#define PCI_CHIP_I810_DC100        0x7123
#define PCI_CHIP_I810_E            0x7125 
#define PCI_CHIP_I815              0x1132 
#endif

#define IS_I810(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I810 ||	\
			imesa->i810Screen->deviceID == PCI_CHIP_I810_DC100 || \
			imesa->i810Screen->deviceID == PCI_CHIP_I810_E)
#define IS_I815(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I815)


#define I810_UPLOAD_TEX(i) (I810_UPLOAD_TEX0<<(i))

/* Use the templated vertex formats:
 */
#define TAG(x) i810##x
#include "tnl_dd/t_dd_vertex.h"
#undef TAG

typedef void (*i810_tri_func)( i810ContextPtr, i810Vertex *, i810Vertex *,
			       i810Vertex * );
typedef void (*i810_line_func)( i810ContextPtr, i810Vertex *, i810Vertex * );
typedef void (*i810_point_func)( i810ContextPtr, i810Vertex * );

struct i810_context_t {
   GLint refcount;   
   GLcontext *glCtx;

   /* Texture object bookkeeping
    */
   unsigned              nr_heaps;
   driTexHeap          * texture_heaps[1];
   driTextureObject      swapped;

   struct i810_texture_object_t *CurrentTexObj[2];


   /* Bit flag to keep track of fallbacks.
    */
   GLuint Fallback;

   /* State for i810vb.c and i810tris.c.
    */
   GLuint new_state;		/* _NEW_* flags */
   GLuint SetupNewInputs;
   GLuint SetupIndex;
   GLuint RenderIndex;
   GLmatrix ViewportMatrix;
   GLenum render_primitive;
   GLenum reduced_primitive;
   GLuint hw_primitive;
   GLubyte *verts;

   drmBufPtr  vertex_buffer;
   char *vertex_addr;
   GLuint vertex_low;
   GLuint vertex_high;
   GLuint vertex_last_prim;
   
   GLboolean upload_cliprects;


   /* Fallback rasterization functions 
    */
   i810_point_func draw_point;
   i810_line_func draw_line;
   i810_tri_func draw_tri;

   /* Hardware state 
    */
   GLuint dirty;		/* I810_UPLOAD_* */
   GLuint Setup[I810_CTX_SETUP_SIZE];
   GLuint BufferSetup[I810_DEST_SETUP_SIZE];
   int vertex_size;
   int vertex_stride_shift;
   unsigned int lastStamp;
   GLboolean stipple_in_hw;

   GLenum TexEnvImageFmt[2];

   /* State which can't be computed completely on the fly:
    */
   GLuint LcsCullMode;
   GLuint LcsLineWidth;
   GLuint LcsPointSize;

   /* Funny mesa mirrors
    */
   GLushort ClearColor;

   /* DRI stuff
    */
   GLuint needClip;
   GLframebuffer *glBuffer;
   GLboolean doPageFlip;

   /* These refer to the current draw (front vs. back) buffer:
    */
   int drawX;			/* origin of drawable in draw buffer */
   int drawY;
   GLuint numClipRects;		/* cliprects for that buffer */
   drm_clip_rect_t *pClipRects;

   int lastSwap;
   int texAge;
   int ctxAge;
   int dirtyAge;
  
 
   GLboolean scissor;
   drm_clip_rect_t draw_rect;
   drm_clip_rect_t scissor_rect;

   drm_context_t hHWContext;
   drm_hw_lock_t *driHwLock;
   int driFd;

   __DRIdrawablePrivate *driDrawable;
   __DRIscreenPrivate *driScreen;
   i810ScreenPrivate *i810Screen; 
   I810SAREAPtr sarea;
};


#define I810_CONTEXT(ctx)    ((i810ContextPtr)(ctx->DriverCtx))

#define GET_DISPATCH_AGE( imesa ) imesa->sarea->last_dispatch
#define GET_ENQUEUE_AGE( imesa ) imesa->sarea->last_enqueue


/* Lock the hardware and validate our state.  
 */
#define LOCK_HARDWARE( imesa )				\
  do {							\
    char __ret=0;					\
    DRM_CAS(imesa->driHwLock, imesa->hHWContext,	\
	    (DRM_LOCK_HELD|imesa->hHWContext), __ret);	\
    if (__ret)						\
        i810GetLock( imesa, 0 );			\
  } while (0)



/* Release the kernel lock.
 */
#define UNLOCK_HARDWARE(imesa)					\
    DRM_UNLOCK(imesa->driFd, imesa->driHwLock, imesa->hHWContext);	


/* This is the wrong way to do it, I'm sure.  Otherwise the drm
 * bitches that I've already got the heavyweight lock.  At worst,
 * this is 3 ioctls.  The best solution probably only gets me down 
 * to 2 ioctls in the worst case.
 */
#define LOCK_HARDWARE_QUIESCENT( imesa ) do {	\
   LOCK_HARDWARE( imesa );			\
   i810RegetLockQuiescent( imesa );		\
} while(0)


extern void i810GetLock( i810ContextPtr imesa, GLuint flags );
extern void i810EmitHwStateLocked( i810ContextPtr imesa );
extern void i810EmitScissorValues( i810ContextPtr imesa, int box_nr, int emit );
extern void i810EmitDrawingRectangle( i810ContextPtr imesa );
extern void i810XMesaSetBackClipRects( i810ContextPtr imesa );
extern void i810XMesaSetFrontClipRects( i810ContextPtr imesa );

#define SUBPIXEL_X -.5
#define SUBPIXEL_Y -.5

/* ================================================================
 * Debugging:
 */
#define DO_DEBUG		1
#if DO_DEBUG
extern int I810_DEBUG;
#else
#define I810_DEBUG		0
#endif

#define DEBUG_TEXTURE	0x1
#define DEBUG_STATE	0x2
#define DEBUG_IOCTL	0x4
#define DEBUG_PRIMS	0x8
#define DEBUG_VERTS	0x10
#define DEBUG_FALLBACKS	0x20
#define DEBUG_VERBOSE	0x40
#define DEBUG_DRI       0x80
#define DEBUG_DMA       0x100
#define DEBUG_SANITY    0x200
#define DEBUG_SYNC      0x400
#define DEBUG_SLEEP     0x800

#endif