Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / trident / trident_context.h
1 /*
2 * Copyright 2002 by Alan Hourihane, Sychdyn, North Wales, UK.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
13 *
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk>
23 *
24 * Trident CyberBladeXP driver.
25 *
26 */
27 #ifndef _TRIDENT_CONTEXT_H_
28 #define _TRIDENT_CONTEXT_H_
29
30 #include "dri_util.h"
31 #include "main/macros.h"
32 #include "main/mtypes.h"
33 #include "drm.h"
34 #include "main/mm.h"
35
36 #define SUBPIXEL_X (0.0F)
37 #define SUBPIXEL_Y (0.125F)
38
39 #define _TRIDENT_NEW_VERTEX (_NEW_TEXTURE | \
40 _DD_NEW_TRI_UNFILLED | \
41 _DD_NEW_TRI_LIGHT_TWOSIDE)
42
43 #define TRIDENT_FALLBACK_TEXTURE 0x01
44 #define TRIDENT_FALLBACK_DRAW_BUFFER 0x02
45
46 #define TRIDENT_NEW_CLIP 0x01
47
48 #define TRIDENT_UPLOAD_COMMAND_D 0x00000001
49 #define TRIDENT_UPLOAD_CONTEXT 0x04000000
50 #define TRIDENT_UPLOAD_CLIPRECTS 0x80000000
51
52 #define TAG(x) trident##x
53 #include "tnl_dd/t_dd_vertex.h"
54 #undef TAG
55
56 /* these require that base be dword-aligned */
57 static INLINE void MMIO_OUT32(unsigned char *base, unsigned int offset,
58 unsigned int val)
59 {
60 unsigned int *addr = (unsigned int *)(base + offset);
61 *addr = val;
62 }
63
64 static INLINE unsigned int MMIO_IN32(unsigned char *base, unsigned int offset)
65 {
66 unsigned int *addr = (unsigned int *)(base + offset);
67 return *addr;
68 }
69
70 #define MMIO_OUT8(base, offset, val) *((base) + (offset)) = (val)
71 #define MMIO_IN8(base, offset) *((base) + (offset))
72
73 struct trident_context;
74 typedef struct trident_context tridentContextRec;
75 typedef struct trident_context *tridentContextPtr;
76
77 typedef void (*trident_quad_func)( tridentContextPtr,
78 const tridentVertex *,
79 const tridentVertex *,
80 const tridentVertex *,
81 const tridentVertex * );
82 typedef void (*trident_tri_func)( tridentContextPtr,
83 const tridentVertex *,
84 const tridentVertex *,
85 const tridentVertex * );
86 typedef void (*trident_line_func)( tridentContextPtr,
87 const tridentVertex *,
88 const tridentVertex * );
89 typedef void (*trident_point_func)( tridentContextPtr,
90 const tridentVertex * );
91
92 typedef struct {
93 drm_handle_t handle; /* Handle to the DRM region */
94 drmSize size; /* Size of the DRM region */
95 unsigned char *map; /* Mapping of the DRM region */
96 } tridentRegionRec, *tridentRegionPtr;
97
98 typedef struct {
99 __DRIscreenPrivate *driScreen; /* Back pointer to DRI screen */
100
101 drmBufMapPtr buffers;
102
103 unsigned int frontOffset;
104 unsigned int frontPitch;
105 unsigned int backOffset;
106 unsigned int backPitch;
107 unsigned int depthOffset;
108 unsigned int depthPitch;
109 unsigned int width;
110 unsigned int height;
111 unsigned int cpp;
112
113 #if 0
114 unsigned int sarea_priv_offset;
115 #endif
116
117 tridentRegionRec mmio;
118 } tridentScreenRec, *tridentScreenPtr;
119
120 /**
121 * tridentRenderbuffer, derived from Mesa's gl_renderbuffer
122 */
123 typedef struct {
124 struct gl_renderbuffer Base;
125 /* XXX per-window info should go here */
126 int foo, bar;
127 } tridentRenderbuffer;
128
129
130 struct trident_context {
131 GLcontext *glCtx; /* Mesa context */
132
133 __DRIcontextPrivate *driContext;
134 __DRIscreenPrivate *driScreen;
135 __DRIdrawablePrivate *driDrawable;
136
137 GLuint new_gl_state;
138 GLuint new_state;
139 GLuint dirty;
140
141 #if 0
142 drm_trident_sarea_t *sarea;
143 #endif
144
145 /* Temporaries for translating away float colors:
146 */
147 struct gl_client_array UbyteColor;
148 struct gl_client_array UbyteSecondaryColor;
149
150 /* Mirrors of some DRI state
151 */
152 int lastStamp; /* mirror driDrawable->lastStamp */
153
154 drm_context_t hHWContext;
155 drmLock *driHwLock;
156 int driFd;
157
158 tridentScreenPtr tridentScreen; /* Screen private DRI data */
159
160 /* Visual, drawable, cliprect and scissor information
161 */
162 GLenum DrawBuffer;
163 GLint drawOffset, drawPitch;
164 GLint drawX, drawY; /* origin of drawable in draw buffer */
165 GLint readOffset, readPitch;
166
167 GLuint numClipRects; /* Cliprects for the draw buffer */
168 drm_clip_rect_t *pClipRects;
169
170 GLint scissor;
171 drm_clip_rect_t ScissorRect; /* Current software scissor */
172
173 GLuint Fallback;
174 GLuint RenderIndex;
175 GLuint SetupNewInputs;
176 GLuint SetupIndex;
177 GLfloat hw_viewport[16];
178 GLfloat depth_scale;
179 GLuint vertex_format;
180 GLuint vertex_size;
181 GLuint vertex_stride_shift;
182 GLubyte *verts;
183
184 GLint tmu_source[2];
185
186 GLuint hw_primitive;
187 GLenum render_primitive;
188
189 trident_point_func draw_point;
190 trident_line_func draw_line;
191 trident_tri_func draw_tri;
192 trident_quad_func draw_quad;
193
194 #if 0
195 gammaTextureObjectPtr CurrentTexObj[2];
196 struct gamma_texture_object_t TexObjList;
197 struct gamma_texture_object_t SwappedOut;
198 GLenum TexEnvImageFmt[2];
199
200 struct mem_block *texHeap;
201
202 int lastSwap;
203 int texAge;
204 int ctxAge;
205 int dirtyAge;
206 int lastStamp;
207 #endif
208
209 /* Chip state */
210
211 int commandD;
212
213 /* Context State */
214
215 int ClearColor;
216 };
217
218 void tridentDDInitExtensions( GLcontext *ctx );
219 void tridentDDInitDriverFuncs( GLcontext *ctx );
220 void tridentDDInitSpanFuncs( GLcontext *ctx );
221 void tridentDDInitState( tridentContextPtr tmesa );
222 void tridentInitHW( tridentContextPtr tmesa );
223 void tridentDDInitStateFuncs( GLcontext *ctx );
224 void tridentDDInitTextureFuncs( GLcontext *ctx );
225 void tridentDDInitTriFuncs( GLcontext *ctx );
226
227 extern void tridentBuildVertices( GLcontext *ctx,
228 GLuint start,
229 GLuint count,
230 GLuint newinputs );
231 extern void tridentInitVB( GLcontext *ctx );
232 extern void tridentCopyBuffer( const __DRIdrawablePrivate *dPriv );
233 extern void tridentFallback( tridentContextPtr tmesa, GLuint bit,
234 GLboolean mode );
235 extern void tridentCheckTexSizes( GLcontext *ctx );
236 extern void tridentChooseVertexState( GLcontext *ctx );
237 extern void tridentDDUpdateHWState( GLcontext *ctx );
238 extern void tridentUploadHwStateLocked( tridentContextPtr tmesa );
239
240 #define TRIDENT_CONTEXT(ctx) ((tridentContextPtr)(ctx->DriverCtx))
241
242 #endif /* _TRIDENT_CONTEXT_H_ */