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 )
66 #define INTEL_WRITE_PART 0x1
67 #define INTEL_WRITE_FULL 0x2
68 #define INTEL_READ 0x4
70 struct intel_texture_object
72 struct gl_texture_object base
; /* The "parent" object */
74 /* The mipmap tree must include at least these levels once
80 GLuint dirty_images
[6];
83 /* On validation any active images held in main memory or in other
84 * regions will be copied to this region and the old storage freed.
86 struct intel_mipmap_tree
*mt
;
93 GLcontext ctx
; /* the parent class */
96 void (*destroy
)( struct intel_context
*intel
);
97 void (*emit_state
)( struct intel_context
*intel
);
98 void (*emit_invarient_state
)( struct intel_context
*intel
);
99 void (*lost_hardware
)( struct intel_context
*intel
);
100 void (*note_fence
)( struct intel_context
*intel
, GLuint fence
);
101 void (*note_unlock
)( struct intel_context
*intel
);
102 void (*update_texture_state
)( struct intel_context
*intel
);
104 void (*render_start
)( struct intel_context
*intel
);
105 void (*set_draw_region
)( struct intel_context
*intel
,
106 struct intel_region
*draw_region
,
107 struct intel_region
*depth_region
);
109 GLuint (*flush_cmd
)( void );
111 void (*emit_flush
)( struct intel_context
*intel
,
114 void (*reduced_primitive_state
)( struct intel_context
*intel
, GLenum rprim
);
116 GLboolean (*check_vertex_size
)( struct intel_context
*intel
, GLuint expected
);
118 void (*invalidate_state
)( struct intel_context
*intel
, GLuint new_state
);
122 void (*install_meta_state
)( struct intel_context
*intel
);
123 void (*leave_meta_state
)( struct intel_context
*intel
);
125 void (*meta_draw_region
)( struct intel_context
*intel
,
126 struct intel_region
*draw_region
,
127 struct intel_region
*depth_region
);
129 void (*meta_color_mask
)( struct intel_context
*intel
,
132 void (*meta_stencil_replace
)( struct intel_context
*intel
,
136 void (*meta_depth_replace
)( struct intel_context
*intel
);
138 void (*meta_texture_blend_replace
) (struct intel_context
* intel
);
140 void (*meta_no_stencil_write
)( struct intel_context
*intel
);
141 void (*meta_no_depth_write
)( struct intel_context
*intel
);
142 void (*meta_no_texture
)( struct intel_context
*intel
);
143 void (*meta_import_pixel_state
) (struct intel_context
* intel
);
144 void (*meta_frame_buffer_texture
)( struct intel_context
*intel
,
145 GLint xoff
, GLint yoff
);
147 void (*meta_draw_quad
)(struct intel_context
*intel
,
148 GLfloat x0
, GLfloat x1
,
149 GLfloat y0
, GLfloat y1
,
151 GLubyte red
, GLubyte green
,
152 GLubyte blue
, GLubyte alpha
,
153 GLfloat s0
, GLfloat s1
,
154 GLfloat t0
, GLfloat t1
);
156 void (*debug_batch
)(struct intel_context
*intel
);
164 unsigned int maxBatchSize
;
166 struct intel_region
*front_region
;
167 struct intel_region
*back_region
;
168 struct intel_region
*third_region
;
169 struct intel_region
*depth_region
;
172 * This value indicates that the kernel memory manager is being used
173 * instead of the fake client-side memory manager.
177 dri_fence
*first_swap_fence
;
178 dri_fence
*last_swap_fence
;
182 struct intel_batchbuffer
*batch
;
185 GLubyte clear_chan
[4];
190 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
191 GLuint depth_clear_mask
;
192 GLuint stencil_clear_mask
;
194 GLboolean hw_stencil
;
195 GLboolean hw_stipple
;
196 GLboolean depth_buffer_is_float
;
199 GLboolean strict_conformance
;
200 GLboolean need_flush
;
202 /* State for intelvb.c and inteltris.c.
204 GLenum render_primitive
;
205 GLenum reduced_primitive
;
207 struct intel_region
*draw_region
;
209 /* These refer to the current draw (front vs. back) buffer:
211 int drawX
; /* origin of drawable in draw buffer */
213 GLuint numClipRects
; /* cliprects for that buffer */
214 drm_clip_rect_t
*pClipRects
;
215 struct gl_texture_object
*frame_buffer_texobj
;
218 drm_clip_rect_t draw_rect
;
219 drm_clip_rect_t scissor_rect
;
221 drm_context_t hHWContext
;
225 __DRIdrawablePrivate
*driDrawable
;
226 __DRIdrawablePrivate
*driReadDrawable
;
227 __DRIscreenPrivate
*driScreen
;
228 intelScreenPrivate
*intelScreen
;
229 volatile drmI830Sarea
*sarea
;
236 * Configuration cache
238 driOptionCache optionCache
;
241 int64_t swap_missed_ust
;
244 GLuint swap_missed_count
;
247 /* These are functions now:
249 void LOCK_HARDWARE( struct intel_context
*intel
);
250 void UNLOCK_HARDWARE( struct intel_context
*intel
);
253 #define SUBPIXEL_X 0.125
254 #define SUBPIXEL_Y 0.125
256 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
258 /* ================================================================
262 #define INTEL_PACKCOLOR4444(r,g,b,a) \
263 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
265 #define INTEL_PACKCOLOR1555(r,g,b,a) \
266 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
269 #define INTEL_PACKCOLOR565(r,g,b) \
270 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
272 #define INTEL_PACKCOLOR8888(r,g,b,a) \
273 ((a<<24) | (r<<16) | (g<<8) | b)
276 #define INTEL_PACKCOLOR(format, r, g, b, a) \
277 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
278 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
279 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
284 /* ================================================================
285 * From linux kernel i386 header files, copes with odd sizes better
286 * than COPY_DWORDS would:
288 #if defined(i386) || defined(__i386__)
289 static inline void * __memcpy(void * to
, const void * from
, size_t n
)
292 __asm__
__volatile__(
297 "1:\ttestb $1,%b4\n\t"
301 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
302 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
307 #define __memcpy(a,b,c) memcpy(a,b,c)
311 /* The system memcpy (at least on ubuntu 5.10) has problems copying
312 * to agp (writecombined) memory from a source which isn't 64-byte
313 * aligned - there is a 4x performance falloff.
315 * The x86 __memcpy is immune to this but is slightly slower
316 * (10%-ish) than the system memcpy.
318 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
319 * isn't much faster than x86_memcpy for agp copies.
321 * TODO: switch dynamically.
323 static inline void *do_memcpy( void *dest
, const void *src
, size_t n
)
325 if ( (((unsigned long)src
) & 63) ||
326 (((unsigned long)dest
) & 63)) {
327 return __memcpy(dest
, src
, n
);
330 return memcpy(dest
, src
, n
);
337 /* ================================================================
340 extern int INTEL_DEBUG
;
342 #define DEBUG_TEXTURE 0x1
343 #define DEBUG_STATE 0x2
344 #define DEBUG_IOCTL 0x4
345 #define DEBUG_PRIMS 0x8
346 #define DEBUG_VERTS 0x10
347 #define DEBUG_FALLBACKS 0x20
348 #define DEBUG_VERBOSE 0x40
349 #define DEBUG_DRI 0x80
350 #define DEBUG_DMA 0x100
351 #define DEBUG_SANITY 0x200
352 #define DEBUG_SYNC 0x400
353 #define DEBUG_SLEEP 0x800
354 #define DEBUG_PIXEL 0x1000
355 #define DEBUG_STATS 0x2000
356 #define DEBUG_TILE 0x4000
357 #define DEBUG_SINGLE_THREAD 0x8000
358 #define DEBUG_WM 0x10000
359 #define DEBUG_URB 0x20000
360 #define DEBUG_VS 0x40000
361 #define DEBUG_BATCH 0x80000
362 #define DEBUG_BUFMGR 0x100000
363 #define DEBUG_BLIT 0x200000
364 #define DEBUG_REGION 0x400000
365 #define DEBUG_MIPTREE 0x800000
367 #define DBG(...) do { \
368 if (INTEL_DEBUG & FILE_DEBUG_FLAG) \
369 _mesa_printf(__VA_ARGS__); \
372 /* ================================================================
376 extern GLboolean
intelInitContext( struct intel_context
*intel
,
377 const __GLcontextModes
*mesaVis
,
378 __DRIcontextPrivate
*driContextPriv
,
379 void *sharedContextPrivate
,
380 struct dd_function_table
*functions
);
382 extern void intelGetLock(struct intel_context
*intel
, GLuint flags
);
384 extern void intelFinish( GLcontext
*ctx
);
385 extern void intelFlush( GLcontext
*ctx
);
387 extern void intelInitDriverFunctions( struct dd_function_table
*functions
);
390 /* ================================================================
393 extern void intelInitStateFuncs( struct dd_function_table
*functions
);
395 #define COMPAREFUNC_ALWAYS 0
396 #define COMPAREFUNC_NEVER 0x1
397 #define COMPAREFUNC_LESS 0x2
398 #define COMPAREFUNC_EQUAL 0x3
399 #define COMPAREFUNC_LEQUAL 0x4
400 #define COMPAREFUNC_GREATER 0x5
401 #define COMPAREFUNC_NOTEQUAL 0x6
402 #define COMPAREFUNC_GEQUAL 0x7
404 #define STENCILOP_KEEP 0
405 #define STENCILOP_ZERO 0x1
406 #define STENCILOP_REPLACE 0x2
407 #define STENCILOP_INCRSAT 0x3
408 #define STENCILOP_DECRSAT 0x4
409 #define STENCILOP_INCR 0x5
410 #define STENCILOP_DECR 0x6
411 #define STENCILOP_INVERT 0x7
413 #define LOGICOP_CLEAR 0
414 #define LOGICOP_NOR 0x1
415 #define LOGICOP_AND_INV 0x2
416 #define LOGICOP_COPY_INV 0x3
417 #define LOGICOP_AND_RVRSE 0x4
418 #define LOGICOP_INV 0x5
419 #define LOGICOP_XOR 0x6
420 #define LOGICOP_NAND 0x7
421 #define LOGICOP_AND 0x8
422 #define LOGICOP_EQUIV 0x9
423 #define LOGICOP_NOOP 0xa
424 #define LOGICOP_OR_INV 0xb
425 #define LOGICOP_COPY 0xc
426 #define LOGICOP_OR_RVRSE 0xd
427 #define LOGICOP_OR 0xe
428 #define LOGICOP_SET 0xf
430 #define BLENDFACT_ZERO 0x01
431 #define BLENDFACT_ONE 0x02
432 #define BLENDFACT_SRC_COLR 0x03
433 #define BLENDFACT_INV_SRC_COLR 0x04
434 #define BLENDFACT_SRC_ALPHA 0x05
435 #define BLENDFACT_INV_SRC_ALPHA 0x06
436 #define BLENDFACT_DST_ALPHA 0x07
437 #define BLENDFACT_INV_DST_ALPHA 0x08
438 #define BLENDFACT_DST_COLR 0x09
439 #define BLENDFACT_INV_DST_COLR 0x0a
440 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
441 #define BLENDFACT_CONST_COLOR 0x0c
442 #define BLENDFACT_INV_CONST_COLOR 0x0d
443 #define BLENDFACT_CONST_ALPHA 0x0e
444 #define BLENDFACT_INV_CONST_ALPHA 0x0f
445 #define BLENDFACT_MASK 0x0f
447 extern int intel_translate_shadow_compare_func( GLenum func
);
448 extern int intel_translate_compare_func( GLenum func
);
449 extern int intel_translate_stencil_op( GLenum op
);
450 extern int intel_translate_blend_factor( GLenum factor
);
451 extern int intel_translate_logic_op( GLenum opcode
);
454 /* ================================================================
457 void intelInitBufferFuncs( struct dd_function_table
*functions
);
459 struct intel_region
*intel_readbuf_region( struct intel_context
*intel
);
460 struct intel_region
*intel_drawbuf_region( struct intel_context
*intel
);
462 extern void intelWindowMoved( struct intel_context
*intel
);
464 extern GLboolean
intel_intersect_cliprects( drm_clip_rect_t
*dest
,
465 const drm_clip_rect_t
*a
,
466 const drm_clip_rect_t
*b
);
469 /* ================================================================
470 * intel_pixel_copy.c:
472 void intelCopyPixels(GLcontext
* ctx
,
473 GLint srcx
, GLint srcy
,
474 GLsizei width
, GLsizei height
,
475 GLint destx
, GLint desty
, GLenum type
);
477 GLboolean
intel_check_blit_fragment_ops(GLcontext
* ctx
);
479 void intelBitmap(GLcontext
* ctx
,
481 GLsizei width
, GLsizei height
,
482 const struct gl_pixelstore_attrib
*unpack
,
483 const GLubyte
* pixels
);
485 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
);
486 #define _NEW_WINDOW_POS 0x40000000
489 /*======================================================================
490 * Inline conversion functions.
491 * These are better-typed than the macros used previously:
493 static inline struct intel_context
*intel_context( GLcontext
*ctx
)
495 return (struct intel_context
*)ctx
;
498 static inline struct intel_texture_object
*intel_texture_object( struct gl_texture_object
*obj
)
500 return (struct intel_texture_object
*)obj
;
503 static inline struct intel_texture_image
*intel_texture_image( struct gl_texture_image
*img
)
505 return (struct intel_texture_image
*)img
;