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
37 #include "intel_screen.h"
38 #include "i830_common.h"
39 #include "tnl/t_vertex.h"
41 #define TAG(x) intel##x
42 #include "tnl_dd/t_dd_vertex.h"
45 #define DV_PF_555 (1<<8)
46 #define DV_PF_565 (2<<8)
47 #define DV_PF_8888 (3<<8)
52 typedef void (*intel_tri_func
)(struct intel_context
*, intelVertex
*, intelVertex
*,
54 typedef void (*intel_line_func
)(struct intel_context
*, intelVertex
*, intelVertex
*);
55 typedef void (*intel_point_func
)(struct intel_context
*, intelVertex
*);
57 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
58 #define INTEL_FALLBACK_READ_BUFFER 0x2
59 #define INTEL_FALLBACK_USER 0x4
60 #define INTEL_FALLBACK_RENDERMODE 0x8
61 #define INTEL_FALLBACK_TEXTURE 0x10
63 extern void intelFallback( struct intel_context
*intel
, GLuint bit
, GLboolean mode
);
64 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
68 struct intel_texture_object
70 struct gl_texture_object base
; /* The "parent" object */
72 /* The mipmap tree must include at least these levels once
78 GLuint dirty_images
[6];
81 /* On validation any active images held in main memory or in other
82 * regions will be copied to this region and the old storage freed.
84 struct intel_mipmap_tree
*mt
;
91 GLcontext ctx
; /* the parent class */
94 void (*destroy
)( struct intel_context
*intel
);
95 void (*emit_state
)( struct intel_context
*intel
);
96 void (*emit_invarient_state
)( struct intel_context
*intel
);
97 void (*lost_hardware
)( struct intel_context
*intel
);
98 void (*note_fence
)( struct intel_context
*intel
, GLuint fence
);
99 void (*note_unlock
)( struct intel_context
*intel
);
100 void (*update_texture_state
)( struct intel_context
*intel
);
102 void (*render_start
)( struct intel_context
*intel
);
103 void (*set_draw_region
)( struct intel_context
*intel
,
104 struct intel_region
*draw_region
,
105 struct intel_region
*depth_region
);
107 GLuint (*flush_cmd
)( void );
109 void (*emit_flush
)( struct intel_context
*intel
,
112 void (*reduced_primitive_state
)( struct intel_context
*intel
, GLenum rprim
);
114 GLboolean (*check_vertex_size
)( struct intel_context
*intel
, GLuint expected
);
116 void (*invalidate_state
)( struct intel_context
*intel
, GLuint new_state
);
120 void (*install_meta_state
)( struct intel_context
*intel
);
121 void (*leave_meta_state
)( struct intel_context
*intel
);
123 void (*meta_draw_region
)( struct intel_context
*intel
,
124 struct intel_region
*draw_region
,
125 struct intel_region
*depth_region
);
127 void (*meta_color_mask
)( struct intel_context
*intel
,
130 void (*meta_stencil_replace
)( struct intel_context
*intel
,
134 void (*meta_depth_replace
)( struct intel_context
*intel
);
136 void (*meta_texture_blend_replace
) (struct intel_context
* intel
);
138 void (*meta_no_stencil_write
)( struct intel_context
*intel
);
139 void (*meta_no_depth_write
)( struct intel_context
*intel
);
140 void (*meta_no_texture
)( struct intel_context
*intel
);
141 void (*meta_import_pixel_state
) (struct intel_context
* intel
);
142 void (*meta_frame_buffer_texture
)( struct intel_context
*intel
,
143 GLint xoff
, GLint yoff
);
145 void (*meta_draw_quad
)(struct intel_context
*intel
,
146 GLfloat x0
, GLfloat x1
,
147 GLfloat y0
, GLfloat y1
,
149 GLubyte red
, GLubyte green
,
150 GLubyte blue
, GLubyte alpha
,
151 GLfloat s0
, GLfloat s1
,
152 GLfloat t0
, GLfloat t1
);
162 GLuint last_swap_fence
;
163 GLuint second_last_swap_fence
;
167 struct intel_batchbuffer
*batch
;
169 GLubyte clear_chan
[4];
174 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
175 GLuint depth_clear_mask
;
176 GLuint stencil_clear_mask
;
178 GLboolean hw_stencil
;
179 GLboolean hw_stipple
;
180 GLboolean depth_buffer_is_float
;
185 GLboolean strict_conformance
;
186 GLboolean need_flush
;
190 /* AGP memory buffer manager:
195 /* State for intelvb.c and inteltris.c.
197 GLenum render_primitive
;
198 GLenum reduced_primitive
;
200 struct intel_region
*front_region
;
201 struct intel_region
*back_region
;
202 struct intel_region
*draw_region
;
203 struct intel_region
*depth_region
;
205 /* These refer to the current draw (front vs. back) buffer:
207 int drawX
; /* origin of drawable in draw buffer */
209 GLuint numClipRects
; /* cliprects for that buffer */
210 drm_clip_rect_t
*pClipRects
;
211 struct gl_texture_object
*frame_buffer_texobj
;
214 drm_clip_rect_t draw_rect
;
215 drm_clip_rect_t scissor_rect
;
217 drm_context_t hHWContext
;
221 __DRIdrawablePrivate
*driDrawable
;
222 __DRIdrawablePrivate
*driReadDrawable
;
223 __DRIscreenPrivate
*driScreen
;
224 intelScreenPrivate
*intelScreen
;
225 volatile drmI830Sarea
*sarea
;
230 * Configuration cache
232 driOptionCache optionCache
;
235 int64_t swap_missed_ust
;
238 GLuint swap_missed_count
;
241 /* These are functions now:
243 void LOCK_HARDWARE( struct intel_context
*intel
);
244 void UNLOCK_HARDWARE( struct intel_context
*intel
);
247 #define SUBPIXEL_X 0.125
248 #define SUBPIXEL_Y 0.125
250 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
252 /* ================================================================
256 #define INTEL_PACKCOLOR4444(r,g,b,a) \
257 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
259 #define INTEL_PACKCOLOR1555(r,g,b,a) \
260 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
263 #define INTEL_PACKCOLOR565(r,g,b) \
264 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
266 #define INTEL_PACKCOLOR8888(r,g,b,a) \
267 ((a<<24) | (r<<16) | (g<<8) | b)
270 #define INTEL_PACKCOLOR(format, r, g, b, a) \
271 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
272 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
273 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
278 /* ================================================================
279 * From linux kernel i386 header files, copes with odd sizes better
280 * than COPY_DWORDS would:
282 #if defined(i386) || defined(__i386__)
283 static inline void * __memcpy(void * to
, const void * from
, size_t n
)
286 __asm__
__volatile__(
291 "1:\ttestb $1,%b4\n\t"
295 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
296 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
301 #define __memcpy(a,b,c) memcpy(a,b,c)
305 /* The system memcpy (at least on ubuntu 5.10) has problems copying
306 * to agp (writecombined) memory from a source which isn't 64-byte
307 * aligned - there is a 4x performance falloff.
309 * The x86 __memcpy is immune to this but is slightly slower
310 * (10%-ish) than the system memcpy.
312 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
313 * isn't much faster than x86_memcpy for agp copies.
315 * TODO: switch dynamically.
317 static inline void *do_memcpy( void *dest
, const void *src
, size_t n
)
319 if ( (((unsigned long)src
) & 63) ||
320 (((unsigned long)dest
) & 63)) {
321 return __memcpy(dest
, src
, n
);
324 return memcpy(dest
, src
, n
);
331 /* ================================================================
334 extern int INTEL_DEBUG
;
336 #define DEBUG_TEXTURE 0x1
337 #define DEBUG_STATE 0x2
338 #define DEBUG_IOCTL 0x4
339 #define DEBUG_PRIMS 0x8
340 #define DEBUG_VERTS 0x10
341 #define DEBUG_FALLBACKS 0x20
342 #define DEBUG_VERBOSE 0x40
343 #define DEBUG_DRI 0x80
344 #define DEBUG_DMA 0x100
345 #define DEBUG_SANITY 0x200
346 #define DEBUG_SYNC 0x400
347 #define DEBUG_SLEEP 0x800
348 #define DEBUG_PIXEL 0x1000
349 #define DEBUG_STATS 0x2000
350 #define DEBUG_TILE 0x4000
351 #define DEBUG_SINGLE_THREAD 0x8000
352 #define DEBUG_WM 0x10000
353 #define DEBUG_URB 0x20000
354 #define DEBUG_VS 0x40000
355 #define DEBUG_BATCH 0x80000
357 /* ================================================================
361 extern GLboolean
intelInitContext( struct intel_context
*intel
,
362 const __GLcontextModes
*mesaVis
,
363 __DRIcontextPrivate
*driContextPriv
,
364 void *sharedContextPrivate
,
365 struct dd_function_table
*functions
);
367 extern void intelGetLock(struct intel_context
*intel
, GLuint flags
);
369 extern void intelFinish( GLcontext
*ctx
);
370 extern void intelFlush( GLcontext
*ctx
);
372 extern void intelInitDriverFunctions( struct dd_function_table
*functions
);
375 /* ================================================================
378 extern void intelInitStateFuncs( struct dd_function_table
*functions
);
380 #define COMPAREFUNC_ALWAYS 0
381 #define COMPAREFUNC_NEVER 0x1
382 #define COMPAREFUNC_LESS 0x2
383 #define COMPAREFUNC_EQUAL 0x3
384 #define COMPAREFUNC_LEQUAL 0x4
385 #define COMPAREFUNC_GREATER 0x5
386 #define COMPAREFUNC_NOTEQUAL 0x6
387 #define COMPAREFUNC_GEQUAL 0x7
389 #define STENCILOP_KEEP 0
390 #define STENCILOP_ZERO 0x1
391 #define STENCILOP_REPLACE 0x2
392 #define STENCILOP_INCRSAT 0x3
393 #define STENCILOP_DECRSAT 0x4
394 #define STENCILOP_INCR 0x5
395 #define STENCILOP_DECR 0x6
396 #define STENCILOP_INVERT 0x7
398 #define LOGICOP_CLEAR 0
399 #define LOGICOP_NOR 0x1
400 #define LOGICOP_AND_INV 0x2
401 #define LOGICOP_COPY_INV 0x3
402 #define LOGICOP_AND_RVRSE 0x4
403 #define LOGICOP_INV 0x5
404 #define LOGICOP_XOR 0x6
405 #define LOGICOP_NAND 0x7
406 #define LOGICOP_AND 0x8
407 #define LOGICOP_EQUIV 0x9
408 #define LOGICOP_NOOP 0xa
409 #define LOGICOP_OR_INV 0xb
410 #define LOGICOP_COPY 0xc
411 #define LOGICOP_OR_RVRSE 0xd
412 #define LOGICOP_OR 0xe
413 #define LOGICOP_SET 0xf
415 #define BLENDFACT_ZERO 0x01
416 #define BLENDFACT_ONE 0x02
417 #define BLENDFACT_SRC_COLR 0x03
418 #define BLENDFACT_INV_SRC_COLR 0x04
419 #define BLENDFACT_SRC_ALPHA 0x05
420 #define BLENDFACT_INV_SRC_ALPHA 0x06
421 #define BLENDFACT_DST_ALPHA 0x07
422 #define BLENDFACT_INV_DST_ALPHA 0x08
423 #define BLENDFACT_DST_COLR 0x09
424 #define BLENDFACT_INV_DST_COLR 0x0a
425 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
426 #define BLENDFACT_CONST_COLOR 0x0c
427 #define BLENDFACT_INV_CONST_COLOR 0x0d
428 #define BLENDFACT_CONST_ALPHA 0x0e
429 #define BLENDFACT_INV_CONST_ALPHA 0x0f
430 #define BLENDFACT_MASK 0x0f
432 extern int intel_translate_shadow_compare_func( GLenum func
);
433 extern int intel_translate_compare_func( GLenum func
);
434 extern int intel_translate_stencil_op( GLenum op
);
435 extern int intel_translate_blend_factor( GLenum factor
);
436 extern int intel_translate_logic_op( GLenum opcode
);
439 /* ================================================================
442 void intelInitBufferFuncs( struct dd_function_table
*functions
);
444 struct intel_region
*intel_readbuf_region( struct intel_context
*intel
);
445 struct intel_region
*intel_drawbuf_region( struct intel_context
*intel
);
447 extern void intelWindowMoved( struct intel_context
*intel
);
449 extern GLboolean
intel_intersect_cliprects( drm_clip_rect_t
*dest
,
450 const drm_clip_rect_t
*a
,
451 const drm_clip_rect_t
*b
);
454 /* ================================================================
455 * intel_pixel_copy.c:
457 void intelCopyPixels(GLcontext
* ctx
,
458 GLint srcx
, GLint srcy
,
459 GLsizei width
, GLsizei height
,
460 GLint destx
, GLint desty
, GLenum type
);
462 GLboolean
intel_check_blit_fragment_ops(GLcontext
* ctx
);
464 void intelBitmap(GLcontext
* ctx
,
466 GLsizei width
, GLsizei height
,
467 const struct gl_pixelstore_attrib
*unpack
,
468 const GLubyte
* pixels
);
470 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
);
471 #define _NEW_WINDOW_POS 0x40000000
474 /*======================================================================
475 * Inline conversion functions.
476 * These are better-typed than the macros used previously:
478 static inline struct intel_context
*intel_context( GLcontext
*ctx
)
480 return (struct intel_context
*)ctx
;
483 static inline struct intel_texture_object
*intel_texture_object( struct gl_texture_object
*obj
)
485 return (struct intel_texture_object
*)obj
;
488 static inline struct intel_texture_image
*intel_texture_image( struct gl_texture_image
*img
)
490 return (struct intel_texture_image
*)img
;