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
36 #include "dri_bufmgr.h"
38 #include "intel_screen.h"
39 #include "intel_tex_obj.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)
54 typedef void (*intel_tri_func
)(struct intel_context
*, intelVertex
*, intelVertex
*,
56 typedef void (*intel_line_func
)(struct intel_context
*, intelVertex
*, intelVertex
*);
57 typedef void (*intel_point_func
)(struct intel_context
*, intelVertex
*);
59 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
60 #define INTEL_FALLBACK_READ_BUFFER 0x2
61 #define INTEL_FALLBACK_USER 0x4
62 #define INTEL_FALLBACK_RENDERMODE 0x8
63 #define INTEL_FALLBACK_TEXTURE 0x10
64 #define INTEL_FALLBACK_DEPTH_BUFFER 0x20
65 #define INTEL_FALLBACK_STENCIL_BUFFER 0x40
67 extern void intelFallback( struct intel_context
*intel
, GLuint bit
, GLboolean mode
);
68 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
70 #define INTEL_WRITE_PART 0x1
71 #define INTEL_WRITE_FULL 0x2
72 #define INTEL_READ 0x4
76 GLcontext ctx
; /* the parent class */
79 void (*destroy
)( struct intel_context
*intel
);
80 void (*emit_state
)( struct intel_context
*intel
);
81 void (*emit_invarient_state
)( struct intel_context
*intel
);
82 void (*lost_hardware
)( struct intel_context
*intel
);
83 void (*note_fence
)( struct intel_context
*intel
, GLuint fence
);
84 void (*note_unlock
)( struct intel_context
*intel
);
85 void (*update_texture_state
)( struct intel_context
*intel
);
87 void (*render_start
)( struct intel_context
*intel
);
88 void (*set_draw_region
)( struct intel_context
*intel
,
89 struct intel_region
*draw_region
,
90 struct intel_region
*depth_region
);
92 GLuint (*flush_cmd
)( void );
94 void (*emit_flush
)( struct intel_context
*intel
,
97 void (*reduced_primitive_state
)( struct intel_context
*intel
, GLenum rprim
);
99 GLboolean (*check_vertex_size
)( struct intel_context
*intel
, GLuint expected
);
101 void (*invalidate_state
)( struct intel_context
*intel
, GLuint new_state
);
105 void (*install_meta_state
)( struct intel_context
*intel
);
106 void (*leave_meta_state
)( struct intel_context
*intel
);
108 void (*meta_draw_region
)( struct intel_context
*intel
,
109 struct intel_region
*draw_region
,
110 struct intel_region
*depth_region
);
112 void (*meta_color_mask
)( struct intel_context
*intel
,
115 void (*meta_stencil_replace
)( struct intel_context
*intel
,
119 void (*meta_depth_replace
)( struct intel_context
*intel
);
121 void (*meta_texture_blend_replace
) (struct intel_context
* intel
);
123 void (*meta_no_stencil_write
)( struct intel_context
*intel
);
124 void (*meta_no_depth_write
)( struct intel_context
*intel
);
125 void (*meta_no_texture
)( struct intel_context
*intel
);
126 void (*meta_import_pixel_state
) (struct intel_context
* intel
);
127 void (*meta_frame_buffer_texture
)( struct intel_context
*intel
,
128 GLint xoff
, GLint yoff
);
130 void (*meta_draw_quad
)(struct intel_context
*intel
,
131 GLfloat x0
, GLfloat x1
,
132 GLfloat y0
, GLfloat y1
,
134 GLuint color
, /* ARGB32 */
135 GLfloat s0
, GLfloat s1
,
136 GLfloat t0
, GLfloat t1
);
138 void (*debug_batch
)(struct intel_context
*intel
);
146 unsigned int maxBatchSize
;
148 struct intel_region
*front_region
;
149 struct intel_region
*back_region
;
150 struct intel_region
*third_region
;
151 struct intel_region
*depth_region
;
154 * This value indicates that the kernel memory manager is being used
155 * instead of the fake client-side memory manager.
159 dri_fence
*first_swap_fence
;
160 dri_fence
*last_swap_fence
;
164 struct intel_batchbuffer
*batch
;
167 GLubyte clear_chan
[4];
168 GLuint ClearColor565
;
169 GLuint ClearColor8888
;
171 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
173 GLboolean hw_stencil
;
174 GLboolean hw_stipple
;
175 GLboolean depth_buffer_is_float
;
178 GLboolean strict_conformance
;
180 /* State for intelvb.c and inteltris.c.
182 GLenum render_primitive
;
183 GLenum reduced_primitive
;
185 struct intel_region
*draw_region
;
187 /* These refer to the current draw (front vs. back) buffer:
189 int drawX
; /* origin of drawable in draw buffer */
191 GLuint numClipRects
; /* cliprects for that buffer */
192 drm_clip_rect_t
*pClipRects
;
193 struct gl_texture_object
*frame_buffer_texobj
;
194 drm_clip_rect_t fboRect
; /**< cliprect for FBO rendering */
197 drm_clip_rect_t draw_rect
;
198 drm_clip_rect_t scissor_rect
;
200 drm_context_t hHWContext
;
204 __DRIdrawablePrivate
*driDrawable
;
205 __DRIdrawablePrivate
*driReadDrawable
;
206 __DRIscreenPrivate
*driScreen
;
207 intelScreenPrivate
*intelScreen
;
208 volatile drmI830Sarea
*sarea
;
215 * Configuration cache
217 driOptionCache optionCache
;
220 int64_t swap_missed_ust
;
223 GLuint swap_missed_count
;
226 /* These are functions now:
228 void LOCK_HARDWARE( struct intel_context
*intel
);
229 void UNLOCK_HARDWARE( struct intel_context
*intel
);
232 #define SUBPIXEL_X 0.125
233 #define SUBPIXEL_Y 0.125
235 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
237 /* ================================================================
241 #define INTEL_PACKCOLOR4444(r,g,b,a) \
242 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
244 #define INTEL_PACKCOLOR1555(r,g,b,a) \
245 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
248 #define INTEL_PACKCOLOR565(r,g,b) \
249 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
251 #define INTEL_PACKCOLOR8888(r,g,b,a) \
252 ((a<<24) | (r<<16) | (g<<8) | b)
255 #define INTEL_PACKCOLOR(format, r, g, b, a) \
256 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
257 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
258 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
263 /* ================================================================
264 * From linux kernel i386 header files, copes with odd sizes better
265 * than COPY_DWORDS would:
267 #if defined(i386) || defined(__i386__)
268 static inline void * __memcpy(void * to
, const void * from
, size_t n
)
271 __asm__
__volatile__(
276 "1:\ttestb $1,%b4\n\t"
280 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
281 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
286 #define __memcpy(a,b,c) memcpy(a,b,c)
290 /* ================================================================
293 extern int INTEL_DEBUG
;
295 #define DEBUG_TEXTURE 0x1
296 #define DEBUG_STATE 0x2
297 #define DEBUG_IOCTL 0x4
298 #define DEBUG_PRIMS 0x8
299 #define DEBUG_VERTS 0x10
300 #define DEBUG_FALLBACKS 0x20
301 #define DEBUG_VERBOSE 0x40
302 #define DEBUG_DRI 0x80
303 #define DEBUG_DMA 0x100
304 #define DEBUG_SANITY 0x200
305 #define DEBUG_SYNC 0x400
306 #define DEBUG_SLEEP 0x800
307 #define DEBUG_PIXEL 0x1000
308 #define DEBUG_STATS 0x2000
309 #define DEBUG_TILE 0x4000
310 #define DEBUG_SINGLE_THREAD 0x8000
311 #define DEBUG_WM 0x10000
312 #define DEBUG_URB 0x20000
313 #define DEBUG_VS 0x40000
314 #define DEBUG_BATCH 0x80000
315 #define DEBUG_BUFMGR 0x100000
316 #define DEBUG_BLIT 0x200000
317 #define DEBUG_REGION 0x400000
318 #define DEBUG_MIPTREE 0x800000
319 #define DEBUG_FBO 0x1000000
321 #define DBG(...) do { \
322 if (INTEL_DEBUG & FILE_DEBUG_FLAG) \
323 _mesa_printf(__VA_ARGS__); \
326 /* ================================================================
330 extern GLboolean
intelInitContext( struct intel_context
*intel
,
331 const __GLcontextModes
*mesaVis
,
332 __DRIcontextPrivate
*driContextPriv
,
333 void *sharedContextPrivate
,
334 struct dd_function_table
*functions
);
336 extern void intelGetLock(struct intel_context
*intel
, GLuint flags
);
338 extern void intelFinish( GLcontext
*ctx
);
339 extern void intelFlush( GLcontext
*ctx
);
341 extern void intelInitDriverFunctions( struct dd_function_table
*functions
);
344 /* ================================================================
347 extern void intelInitStateFuncs( struct dd_function_table
*functions
);
349 #define COMPAREFUNC_ALWAYS 0
350 #define COMPAREFUNC_NEVER 0x1
351 #define COMPAREFUNC_LESS 0x2
352 #define COMPAREFUNC_EQUAL 0x3
353 #define COMPAREFUNC_LEQUAL 0x4
354 #define COMPAREFUNC_GREATER 0x5
355 #define COMPAREFUNC_NOTEQUAL 0x6
356 #define COMPAREFUNC_GEQUAL 0x7
358 #define STENCILOP_KEEP 0
359 #define STENCILOP_ZERO 0x1
360 #define STENCILOP_REPLACE 0x2
361 #define STENCILOP_INCRSAT 0x3
362 #define STENCILOP_DECRSAT 0x4
363 #define STENCILOP_INCR 0x5
364 #define STENCILOP_DECR 0x6
365 #define STENCILOP_INVERT 0x7
367 #define LOGICOP_CLEAR 0
368 #define LOGICOP_NOR 0x1
369 #define LOGICOP_AND_INV 0x2
370 #define LOGICOP_COPY_INV 0x3
371 #define LOGICOP_AND_RVRSE 0x4
372 #define LOGICOP_INV 0x5
373 #define LOGICOP_XOR 0x6
374 #define LOGICOP_NAND 0x7
375 #define LOGICOP_AND 0x8
376 #define LOGICOP_EQUIV 0x9
377 #define LOGICOP_NOOP 0xa
378 #define LOGICOP_OR_INV 0xb
379 #define LOGICOP_COPY 0xc
380 #define LOGICOP_OR_RVRSE 0xd
381 #define LOGICOP_OR 0xe
382 #define LOGICOP_SET 0xf
384 #define BLENDFACT_ZERO 0x01
385 #define BLENDFACT_ONE 0x02
386 #define BLENDFACT_SRC_COLR 0x03
387 #define BLENDFACT_INV_SRC_COLR 0x04
388 #define BLENDFACT_SRC_ALPHA 0x05
389 #define BLENDFACT_INV_SRC_ALPHA 0x06
390 #define BLENDFACT_DST_ALPHA 0x07
391 #define BLENDFACT_INV_DST_ALPHA 0x08
392 #define BLENDFACT_DST_COLR 0x09
393 #define BLENDFACT_INV_DST_COLR 0x0a
394 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
395 #define BLENDFACT_CONST_COLOR 0x0c
396 #define BLENDFACT_INV_CONST_COLOR 0x0d
397 #define BLENDFACT_CONST_ALPHA 0x0e
398 #define BLENDFACT_INV_CONST_ALPHA 0x0f
399 #define BLENDFACT_MASK 0x0f
401 extern int intel_translate_shadow_compare_func( GLenum func
);
402 extern int intel_translate_compare_func( GLenum func
);
403 extern int intel_translate_stencil_op( GLenum op
);
404 extern int intel_translate_blend_factor( GLenum factor
);
405 extern int intel_translate_logic_op( GLenum opcode
);
408 /* ================================================================
411 void intelInitBufferFuncs( struct dd_function_table
*functions
);
413 struct intel_region
*intel_readbuf_region( struct intel_context
*intel
);
414 struct intel_region
*intel_drawbuf_region( struct intel_context
*intel
);
416 extern void intelWindowMoved( struct intel_context
*intel
);
418 extern GLboolean
intel_intersect_cliprects( drm_clip_rect_t
*dest
,
419 const drm_clip_rect_t
*a
,
420 const drm_clip_rect_t
*b
);
423 /* ================================================================
424 * intel_pixel_copy.c:
426 void intelCopyPixels(GLcontext
* ctx
,
427 GLint srcx
, GLint srcy
,
428 GLsizei width
, GLsizei height
,
429 GLint destx
, GLint desty
, GLenum type
);
431 GLboolean
intel_check_blit_fragment_ops(GLcontext
* ctx
);
433 void intelBitmap(GLcontext
* ctx
,
435 GLsizei width
, GLsizei height
,
436 const struct gl_pixelstore_attrib
*unpack
,
437 const GLubyte
* pixels
);
439 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
);
440 #define _NEW_WINDOW_POS 0x40000000
443 /*======================================================================
444 * Inline conversion functions.
445 * These are better-typed than the macros used previously:
447 static inline struct intel_context
*intel_context( GLcontext
*ctx
)
449 return (struct intel_context
*)ctx
;