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"
40 #include "i830_common.h"
41 #include "tnl/t_vertex.h"
43 #define TAG(x) intel##x
44 #include "tnl_dd/t_dd_vertex.h"
47 #define DV_PF_555 (1<<8)
48 #define DV_PF_565 (2<<8)
49 #define DV_PF_8888 (3<<8)
51 #define INTEL_CONTEXT(ctx) ((intelContextPtr)(ctx))
53 typedef struct intel_context intelContext
;
54 typedef struct intel_context
*intelContextPtr
;
55 typedef struct intel_texture_object
*intelTextureObjectPtr
;
57 typedef void (*intel_tri_func
)(intelContextPtr
, intelVertex
*, intelVertex
*,
59 typedef void (*intel_line_func
)(intelContextPtr
, intelVertex
*, intelVertex
*);
60 typedef void (*intel_point_func
)(intelContextPtr
, intelVertex
*);
62 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
63 #define INTEL_FALLBACK_READ_BUFFER 0x2
64 #define INTEL_FALLBACK_USER 0x4
65 #define INTEL_FALLBACK_NO_BATCHBUFFER 0x8
66 #define INTEL_FALLBACK_NO_TEXMEM 0x10
67 #define INTEL_FALLBACK_RENDERMODE 0x20
69 extern void intelFallback( intelContextPtr intel
, GLuint bit
, GLboolean mode
);
70 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
73 #define INTEL_TEX_MAXLEVELS 10
76 struct intel_texture_object
78 driTextureObject base
; /* the parent class */
92 const struct gl_texture_image
*image
;
93 GLuint offset
; /* into BufAddr */
95 GLuint internalFormat
;
96 } image
[6][INTEL_TEX_MAXLEVELS
];
99 GLuint firstLevel
,lastLevel
;
105 GLcontext ctx
; /* the parent class */
108 void (*destroy
)( intelContextPtr intel
);
109 void (*emit_state
)( intelContextPtr intel
);
110 void (*emit_invarient_state
)( intelContextPtr intel
);
111 void (*lost_hardware
)( intelContextPtr intel
);
112 void (*update_texture_state
)( intelContextPtr intel
);
114 void (*render_start
)( intelContextPtr intel
);
115 void (*set_color_region
)( intelContextPtr intel
, const intelRegion
*reg
);
116 void (*set_z_region
)( intelContextPtr intel
, const intelRegion
*reg
);
117 void (*update_color_z_regions
)(intelContextPtr intel
,
118 const intelRegion
*colorRegion
,
119 const intelRegion
*depthRegion
);
120 void (*emit_flush
)( intelContextPtr intel
);
121 void (*reduced_primitive_state
)( intelContextPtr intel
, GLenum rprim
);
123 GLboolean (*check_vertex_size
)( intelContextPtr intel
, GLuint expected
);
125 void (*clear_with_tris
)( intelContextPtr intel
, GLbitfield mask
,
127 GLint cx
, GLint cy
, GLint cw
, GLint ch
);
129 void (*rotate_window
)( intelContextPtr intel
,
130 __DRIdrawablePrivate
*dPriv
, GLuint srcBuf
);
132 intelTextureObjectPtr (*alloc_tex_obj
)( struct gl_texture_object
*tObj
);
146 GLuint last_emit_state
;
147 GLboolean contains_geometry
;
163 void (*flush
)( GLcontext
* );
178 /* Support for duplicating XYZW as WPOS parameter (crutch for I915).
183 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
184 GLuint vertex_attr_count
;
187 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
188 GLuint depth_clear_mask
;
189 GLuint stencil_clear_mask
;
191 GLboolean hw_stencil
;
192 GLboolean hw_stipple
;
194 /* Texture object bookkeeping
197 driTexHeap
* texture_heaps
[1];
198 driTextureObject swapped
;
201 struct intel_texture_object
*CurrentTexObj
[MAX_TEXTURE_UNITS
];
203 /* State for intelvb.c and inteltris.c.
206 GLmatrix ViewportMatrix
;
207 GLenum render_primitive
;
208 GLenum reduced_primitive
;
210 unsigned char *verts
; /* points to tnl->clipspace.vertex_buf */
213 /* Fallback rasterization functions
215 intel_point_func draw_point
;
216 intel_line_func draw_line
;
217 intel_tri_func draw_tri
;
219 /* Drawing buffer state
221 intelRegion
*drawRegion
; /* current drawing buffer */
222 intelRegion
*readRegion
; /* current reading buffer */
224 int drawX
; /* origin of drawable in draw buffer */
226 GLuint numClipRects
; /* cliprects for that buffer */
227 drm_clip_rect_t
*pClipRects
;
235 drm_i915_irq_wait_t iw
;
238 drm_clip_rect_t draw_rect
;
239 drm_clip_rect_t scissor_rect
;
241 drm_context_t hHWContext
;
245 __DRIdrawablePrivate
*driDrawable
;
246 __DRIscreenPrivate
*driScreen
;
247 intelScreenPrivate
*intelScreen
;
251 * Configuration cache
253 driOptionCache optionCache
;
261 int64_t swap_missed_ust
;
264 GLuint swap_missed_count
;
268 #define DEBUG_LOCKING 1
271 extern char *prevLockFile
;
272 extern int prevLockLine
;
274 #define DEBUG_LOCK() \
276 prevLockFile = (__FILE__); \
277 prevLockLine = (__LINE__); \
280 #define DEBUG_RESET() \
286 /* Slightly less broken way of detecting recursive locking in a
287 * threaded environment. The right way to do this would be to make
288 * prevLockFile, prevLockLine thread-local.
290 * This technique instead checks to see if the same context is
291 * requesting the lock twice -- this will not catch application
292 * breakages where the same context is active in two different threads
293 * at once, but it will catch driver breakages (recursive locking) in
296 #define DEBUG_CHECK_LOCK() \
298 if ( *((volatile int *)intel->driHwLock) == \
299 (DRM_LOCK_HELD | intel->hHWContext) ) { \
301 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
302 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
310 #define DEBUG_RESET()
311 #define DEBUG_CHECK_LOCK()
318 /* Lock the hardware and validate our state.
320 #define LOCK_HARDWARE( intel ) \
323 DEBUG_CHECK_LOCK(); \
324 assert(!(intel)->locked); \
325 DRM_CAS((intel)->driHwLock, (intel)->hHWContext, \
326 (DRM_LOCK_HELD|(intel)->hHWContext), __ret); \
328 intelGetLock( (intel), 0 ); \
330 (intel)->locked = 1; \
334 /* Unlock the hardware using the global current context
336 #define UNLOCK_HARDWARE(intel) \
340 intel->perf_boxes |= intel->sarea->perf_boxes; \
341 intel->sarea->perf_boxes = 0; \
343 DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext); \
348 #define SUBPIXEL_X 0.125
349 #define SUBPIXEL_Y 0.125
351 #define INTEL_FIREVERTICES(intel) \
353 if ((intel)->prim.flush) \
354 (intel)->prim.flush(&(intel)->ctx); \
357 /* ================================================================
361 #define INTEL_PACKCOLOR4444(r,g,b,a) \
362 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
364 #define INTEL_PACKCOLOR1555(r,g,b,a) \
365 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
368 #define INTEL_PACKCOLOR565(r,g,b) \
369 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
371 #define INTEL_PACKCOLOR8888(r,g,b,a) \
372 ((a<<24) | (r<<16) | (g<<8) | b)
375 #define INTEL_PACKCOLOR(format, r, g, b, a) \
376 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
377 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
378 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
383 /* ================================================================
384 * From linux kernel i386 header files, copes with odd sizes better
385 * than COPY_DWORDS would:
387 #if defined(i386) || defined(__i386__)
388 static __inline__
void * __memcpy(void * to
, const void * from
, size_t n
)
391 __asm__
__volatile__(
396 "1:\ttestb $1,%b4\n\t"
400 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
401 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
406 #define __memcpy(a,b,c) memcpy(a,b,c)
411 /* ================================================================
416 extern int INTEL_DEBUG
;
418 #define INTEL_DEBUG 0
421 #define DEBUG_TEXTURE 0x1
422 #define DEBUG_STATE 0x2
423 #define DEBUG_IOCTL 0x4
424 #define DEBUG_PRIMS 0x8
425 #define DEBUG_VERTS 0x10
426 #define DEBUG_FALLBACKS 0x20
427 #define DEBUG_VERBOSE 0x40
428 #define DEBUG_DRI 0x80
429 #define DEBUG_DMA 0x100
430 #define DEBUG_SANITY 0x200
431 #define DEBUG_SYNC 0x400
432 #define DEBUG_SLEEP 0x800
433 #define DEBUG_PIXEL 0x1000
436 #define PCI_CHIP_845_G 0x2562
437 #define PCI_CHIP_I830_M 0x3577
438 #define PCI_CHIP_I855_GM 0x3582
439 #define PCI_CHIP_I865_G 0x2572
440 #define PCI_CHIP_I915_G 0x2582
441 #define PCI_CHIP_I915_GM 0x2592
442 #define PCI_CHIP_I945_G 0x2772
443 #define PCI_CHIP_I945_GM 0x27A2
446 /* ================================================================
450 extern void intelInitDriverFunctions( struct dd_function_table
*functions
);
452 extern GLboolean
intelInitContext( intelContextPtr intel
,
453 const __GLcontextModes
*mesaVis
,
454 __DRIcontextPrivate
*driContextPriv
,
455 void *sharedContextPrivate
,
456 struct dd_function_table
*functions
);
458 extern void intelGetLock(intelContextPtr intel
, GLuint flags
);
459 extern void intelSetBackClipRects(intelContextPtr intel
);
460 extern void intelSetFrontClipRects(intelContextPtr intel
);
461 extern void intelWindowMoved( intelContextPtr intel
);
463 extern void intelInitState( GLcontext
*ctx
);
464 extern const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
);
467 /* ================================================================
470 extern void intelInitStateFuncs( struct dd_function_table
*functions
);
472 #define COMPAREFUNC_ALWAYS 0
473 #define COMPAREFUNC_NEVER 0x1
474 #define COMPAREFUNC_LESS 0x2
475 #define COMPAREFUNC_EQUAL 0x3
476 #define COMPAREFUNC_LEQUAL 0x4
477 #define COMPAREFUNC_GREATER 0x5
478 #define COMPAREFUNC_NOTEQUAL 0x6
479 #define COMPAREFUNC_GEQUAL 0x7
481 #define STENCILOP_KEEP 0
482 #define STENCILOP_ZERO 0x1
483 #define STENCILOP_REPLACE 0x2
484 #define STENCILOP_INCRSAT 0x3
485 #define STENCILOP_DECRSAT 0x4
486 #define STENCILOP_INCR 0x5
487 #define STENCILOP_DECR 0x6
488 #define STENCILOP_INVERT 0x7
490 #define LOGICOP_CLEAR 0
491 #define LOGICOP_NOR 0x1
492 #define LOGICOP_AND_INV 0x2
493 #define LOGICOP_COPY_INV 0x3
494 #define LOGICOP_AND_RVRSE 0x4
495 #define LOGICOP_INV 0x5
496 #define LOGICOP_XOR 0x6
497 #define LOGICOP_NAND 0x7
498 #define LOGICOP_AND 0x8
499 #define LOGICOP_EQUIV 0x9
500 #define LOGICOP_NOOP 0xa
501 #define LOGICOP_OR_INV 0xb
502 #define LOGICOP_COPY 0xc
503 #define LOGICOP_OR_RVRSE 0xd
504 #define LOGICOP_OR 0xe
505 #define LOGICOP_SET 0xf
507 #define BLENDFACT_ZERO 0x01
508 #define BLENDFACT_ONE 0x02
509 #define BLENDFACT_SRC_COLR 0x03
510 #define BLENDFACT_INV_SRC_COLR 0x04
511 #define BLENDFACT_SRC_ALPHA 0x05
512 #define BLENDFACT_INV_SRC_ALPHA 0x06
513 #define BLENDFACT_DST_ALPHA 0x07
514 #define BLENDFACT_INV_DST_ALPHA 0x08
515 #define BLENDFACT_DST_COLR 0x09
516 #define BLENDFACT_INV_DST_COLR 0x0a
517 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
518 #define BLENDFACT_CONST_COLOR 0x0c
519 #define BLENDFACT_INV_CONST_COLOR 0x0d
520 #define BLENDFACT_CONST_ALPHA 0x0e
521 #define BLENDFACT_INV_CONST_ALPHA 0x0f
522 #define BLENDFACT_MASK 0x0f
525 extern int intel_translate_compare_func( GLenum func
);
526 extern int intel_translate_stencil_op( GLenum op
);
527 extern int intel_translate_blend_factor( GLenum factor
);
528 extern int intel_translate_logic_op( GLenum opcode
);
531 /* ================================================================
534 extern void intel_dump_batchbuffer( long offset
,
539 /* ================================================================
542 extern void intelInitPixelFuncs( struct dd_function_table
*functions
);