1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #ifndef INTELCONTEXT_INC
29 #define INTELCONTEXT_INC
38 #include "intel_screen.h"
39 #include "i830_common.h"
40 #include "tnl/t_vertex.h"
42 #define TAG(x) intel##x
43 #include "tnl_dd/t_dd_vertex.h"
46 #define DV_PF_555 (1<<8)
47 #define DV_PF_565 (2<<8)
48 #define DV_PF_8888 (3<<8)
50 #define INTEL_CONTEXT(ctx) ((intelContextPtr)(ctx))
52 typedef struct intel_context intelContext
;
53 typedef struct intel_context
*intelContextPtr
;
54 typedef struct intel_texture_object
*intelTextureObjectPtr
;
56 typedef void (*intel_tri_func
)(intelContextPtr
, intelVertex
*, intelVertex
*,
58 typedef void (*intel_line_func
)(intelContextPtr
, intelVertex
*, intelVertex
*);
59 typedef void (*intel_point_func
)(intelContextPtr
, intelVertex
*);
61 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
62 #define INTEL_FALLBACK_READ_BUFFER 0x2
63 #define INTEL_FALLBACK_USER 0x4
64 #define INTEL_FALLBACK_NO_BATCHBUFFER 0x8
65 #define INTEL_FALLBACK_NO_TEXMEM 0x10
66 #define INTEL_FALLBACK_RENDERMODE 0x20
68 extern void intelFallback( intelContextPtr intel
, GLuint bit
, GLboolean mode
);
69 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
72 #define INTEL_TEX_MAXLEVELS 10
75 struct intel_texture_object
77 driTextureObject base
; /* the parent class */
91 const struct gl_texture_image
*image
;
92 GLuint offset
; /* into BufAddr */
94 GLuint internalFormat
;
95 } image
[6][INTEL_TEX_MAXLEVELS
];
98 GLuint firstLevel
,lastLevel
;
104 GLcontext ctx
; /* the parent class */
107 void (*destroy
)( intelContextPtr intel
);
108 void (*emit_state
)( intelContextPtr intel
);
109 void (*emit_invarient_state
)( intelContextPtr intel
);
110 void (*lost_hardware
)( intelContextPtr intel
);
111 void (*update_texture_state
)( intelContextPtr intel
);
113 void (*render_start
)( intelContextPtr intel
);
114 void (*set_draw_offset
)( intelContextPtr intel
, int offset
);
115 void (*emit_flush
)( intelContextPtr intel
);
117 void (*reduced_primitive_state
)( intelContextPtr intel
, GLenum rprim
);
119 GLboolean (*check_vertex_size
)( intelContextPtr intel
, GLuint expected
);
121 void (*clear_with_tris
)( intelContextPtr intel
, GLbitfield mask
,
123 GLint cx
, GLint cy
, GLint cw
, GLint ch
);
125 intelTextureObjectPtr (*alloc_tex_obj
)( struct gl_texture_object
*tObj
);
151 void (*flush
)( GLcontext
* );
166 /* Support for duplicating XYZW as WPOS parameter (crutch for I915).
171 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
172 GLuint vertex_attr_count
;
175 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
176 GLuint depth_clear_mask
;
177 GLuint stencil_clear_mask
;
179 GLboolean hw_stencil
;
180 GLboolean hw_stipple
;
182 /* Texture object bookkeeping
185 driTexHeap
* texture_heaps
[1];
186 driTextureObject swapped
;
189 struct intel_texture_object
*CurrentTexObj
[MAX_TEXTURE_UNITS
];
191 /* State for intelvb.c and inteltris.c.
194 GLmatrix ViewportMatrix
;
195 GLenum render_primitive
;
196 GLenum reduced_primitive
;
198 char *verts
; /* points to tnl->clipspace.vertex_buf */
201 /* Fallback rasterization functions
203 intel_point_func draw_point
;
204 intel_line_func draw_line
;
205 intel_tri_func draw_tri
;
207 /* These refer to the current draw (front vs. back) buffer:
209 char *drawMap
; /* draw buffer address in virtual mem */
211 GLuint drawOffset
; /* agp offset of drawbuffer */
212 int drawX
; /* origin of drawable in draw buffer */
214 GLuint numClipRects
; /* cliprects for that buffer */
215 drm_clip_rect_t
*pClipRects
;
222 drm_clip_rect_t draw_rect
;
223 drm_clip_rect_t scissor_rect
;
225 drm_context_t hHWContext
;
229 __DRIdrawablePrivate
*driDrawable
;
230 __DRIscreenPrivate
*driScreen
;
231 intelScreenPrivate
*intelScreen
;
235 * Configuration cache
237 driOptionCache optionCache
;
241 #define DEBUG_LOCKING 1
244 extern char *prevLockFile
;
245 extern int prevLockLine
;
247 #define DEBUG_LOCK() \
249 prevLockFile = (__FILE__); \
250 prevLockLine = (__LINE__); \
253 #define DEBUG_RESET() \
259 /* Slightly less broken way of detecting recursive locking in a
260 * threaded environment. The right way to do this would be to make
261 * prevLockFile, prevLockLine thread-local.
263 * This technique instead checks to see if the same context is
264 * requesting the lock twice -- this will not catch application
265 * breakages where the same context is active in two different threads
266 * at once, but it will catch driver breakages (recursive locking) in
269 #define DEBUG_CHECK_LOCK() \
271 if ( *((volatile int *)intel->driHwLock) == \
272 (DRM_LOCK_HELD | intel->hHWContext) ) { \
274 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
275 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
283 #define DEBUG_RESET()
284 #define DEBUG_CHECK_LOCK()
291 /* Lock the hardware and validate our state.
293 #define LOCK_HARDWARE( intel ) \
296 DEBUG_CHECK_LOCK(); \
297 assert(!(intel)->locked); \
298 DRM_CAS((intel)->driHwLock, (intel)->hHWContext, \
299 (DRM_LOCK_HELD|(intel)->hHWContext), __ret); \
301 intelGetLock( (intel), 0 ); \
303 (intel)->locked = 1; \
307 /* Unlock the hardware using the global current context
309 #define UNLOCK_HARDWARE(intel) \
313 intel->perf_boxes |= intel->sarea->perf_boxes; \
314 intel->sarea->perf_boxes = 0; \
316 DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext); \
321 #define SUBPIXEL_X 0.125
322 #define SUBPIXEL_Y 0.125
324 #define INTEL_FIREVERTICES(intel) \
326 if ((intel)->prim.flush) \
327 (intel)->prim.flush(&(intel)->ctx); \
330 /* ================================================================
334 #define INTEL_PACKCOLOR4444(r,g,b,a) \
335 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
337 #define INTEL_PACKCOLOR1555(r,g,b,a) \
338 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
341 #define INTEL_PACKCOLOR565(r,g,b) \
342 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
344 #define INTEL_PACKCOLOR8888(r,g,b,a) \
345 ((a<<24) | (r<<16) | (g<<8) | b)
348 #define INTEL_PACKCOLOR(format, r, g, b, a) \
349 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
350 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
351 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
356 /* ================================================================
357 * From linux kernel i386 header files, copes with odd sizes better
358 * than COPY_DWORDS would:
361 static __inline__
void * __memcpy(void * to
, const void * from
, size_t n
)
364 __asm__
__volatile__(
369 "1:\ttestb $1,%b4\n\t"
373 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
374 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
379 #define __memcpy(a,b,c) memcpy(a,b,c)
384 /* ================================================================
389 extern int INTEL_DEBUG
;
391 #define INTEL_DEBUG 0
394 #define DEBUG_TEXTURE 0x1
395 #define DEBUG_STATE 0x2
396 #define DEBUG_IOCTL 0x4
397 #define DEBUG_PRIMS 0x8
398 #define DEBUG_VERTS 0x10
399 #define DEBUG_FALLBACKS 0x20
400 #define DEBUG_VERBOSE 0x40
401 #define DEBUG_DRI 0x80
402 #define DEBUG_DMA 0x100
403 #define DEBUG_SANITY 0x200
404 #define DEBUG_SYNC 0x400
405 #define DEBUG_SLEEP 0x800
406 #define DEBUG_PIXEL 0x1000
409 #define PCI_CHIP_845_G 0x2562
410 #define PCI_CHIP_I830_M 0x3577
411 #define PCI_CHIP_I855_GM 0x3582
412 #define PCI_CHIP_I865_G 0x2572
413 #define PCI_CHIP_I915_G 0x2582
416 /* ================================================================
420 extern void intelInitDriverFunctions( struct dd_function_table
*functions
);
422 extern GLboolean
intelInitContext( intelContextPtr intel
,
423 const __GLcontextModes
*mesaVis
,
424 __DRIcontextPrivate
*driContextPriv
,
425 void *sharedContextPrivate
,
426 struct dd_function_table
*functions
);
428 extern void intelGetLock(intelContextPtr intel
, GLuint flags
);
429 extern void intelSetBackClipRects(intelContextPtr intel
);
430 extern void intelSetFrontClipRects(intelContextPtr intel
);
431 extern void intelWindowMoved( intelContextPtr intel
);
433 extern void intelInitState( GLcontext
*ctx
);
434 extern const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
);
437 /* ================================================================
440 extern void intelInitStateFuncs( struct dd_function_table
*functions
);
443 /* ================================================================
446 extern void intel_dump_batchbuffer( long offset
,
451 /* ================================================================
454 extern void intelInitPixelFuncs( struct dd_function_table
*functions
);