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 "intel_tex_obj.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)
53 typedef void (*intel_tri_func
)(struct intel_context
*, intelVertex
*, intelVertex
*,
55 typedef void (*intel_line_func
)(struct intel_context
*, intelVertex
*, intelVertex
*);
56 typedef void (*intel_point_func
)(struct intel_context
*, intelVertex
*);
58 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
59 #define INTEL_FALLBACK_READ_BUFFER 0x2
60 #define INTEL_FALLBACK_USER 0x4
61 #define INTEL_FALLBACK_RENDERMODE 0x8
62 #define INTEL_FALLBACK_TEXTURE 0x10
64 extern void intelFallback( struct intel_context
*intel
, GLuint bit
, GLboolean mode
);
65 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
67 #define INTEL_WRITE_PART 0x1
68 #define INTEL_WRITE_FULL 0x2
69 #define INTEL_READ 0x4
73 GLcontext ctx
; /* the parent class */
76 void (*destroy
)( struct intel_context
*intel
);
77 void (*emit_state
)( struct intel_context
*intel
);
78 void (*emit_invarient_state
)( struct intel_context
*intel
);
79 void (*lost_hardware
)( struct intel_context
*intel
);
80 void (*note_fence
)( struct intel_context
*intel
, GLuint fence
);
81 void (*note_unlock
)( struct intel_context
*intel
);
82 void (*update_texture_state
)( struct intel_context
*intel
);
84 void (*render_start
)( struct intel_context
*intel
);
85 void (*set_draw_region
)( struct intel_context
*intel
,
86 struct intel_region
*draw_region
,
87 struct intel_region
*depth_region
);
89 GLuint (*flush_cmd
)( void );
91 void (*emit_flush
)( struct intel_context
*intel
,
94 void (*reduced_primitive_state
)( struct intel_context
*intel
, GLenum rprim
);
96 GLboolean (*check_vertex_size
)( struct intel_context
*intel
, GLuint expected
);
98 void (*invalidate_state
)( struct intel_context
*intel
, GLuint new_state
);
102 void (*install_meta_state
)( struct intel_context
*intel
);
103 void (*leave_meta_state
)( struct intel_context
*intel
);
105 void (*meta_draw_region
)( struct intel_context
*intel
,
106 struct intel_region
*draw_region
,
107 struct intel_region
*depth_region
);
109 void (*meta_color_mask
)( struct intel_context
*intel
,
112 void (*meta_stencil_replace
)( struct intel_context
*intel
,
116 void (*meta_depth_replace
)( struct intel_context
*intel
);
118 void (*meta_texture_blend_replace
) (struct intel_context
* intel
);
120 void (*meta_no_stencil_write
)( struct intel_context
*intel
);
121 void (*meta_no_depth_write
)( struct intel_context
*intel
);
122 void (*meta_no_texture
)( struct intel_context
*intel
);
123 void (*meta_import_pixel_state
) (struct intel_context
* intel
);
124 void (*meta_frame_buffer_texture
)( struct intel_context
*intel
,
125 GLint xoff
, GLint yoff
);
127 void (*meta_draw_quad
)(struct intel_context
*intel
,
128 GLfloat x0
, GLfloat x1
,
129 GLfloat y0
, GLfloat y1
,
131 GLubyte red
, GLubyte green
,
132 GLubyte blue
, GLubyte alpha
,
133 GLfloat s0
, GLfloat s1
,
134 GLfloat t0
, GLfloat t1
);
136 void (*debug_batch
)(struct intel_context
*intel
);
144 unsigned int maxBatchSize
;
146 struct intel_region
*front_region
;
147 struct intel_region
*back_region
;
148 struct intel_region
*third_region
;
149 struct intel_region
*depth_region
;
152 * This value indicates that the kernel memory manager is being used
153 * instead of the fake client-side memory manager.
157 dri_fence
*first_swap_fence
;
158 dri_fence
*last_swap_fence
;
162 struct intel_batchbuffer
*batch
;
165 GLubyte clear_chan
[4];
170 GLfloat polygon_offset_scale
; /* dependent on depth_scale, bpp */
171 GLuint depth_clear_mask
;
172 GLuint stencil_clear_mask
;
174 GLboolean hw_stencil
;
175 GLboolean hw_stipple
;
176 GLboolean depth_buffer_is_float
;
179 GLboolean strict_conformance
;
180 GLboolean need_flush
;
182 /* State for intelvb.c and inteltris.c.
184 GLenum render_primitive
;
185 GLenum reduced_primitive
;
187 struct intel_region
*draw_region
;
189 /* These refer to the current draw (front vs. back) buffer:
191 int drawX
; /* origin of drawable in draw buffer */
193 GLuint numClipRects
; /* cliprects for that buffer */
194 drm_clip_rect_t
*pClipRects
;
195 struct gl_texture_object
*frame_buffer_texobj
;
198 drm_clip_rect_t draw_rect
;
199 drm_clip_rect_t scissor_rect
;
201 drm_context_t hHWContext
;
205 __DRIdrawablePrivate
*driDrawable
;
206 __DRIdrawablePrivate
*driReadDrawable
;
207 __DRIscreenPrivate
*driScreen
;
208 intelScreenPrivate
*intelScreen
;
209 volatile drmI830Sarea
*sarea
;
216 * Configuration cache
218 driOptionCache optionCache
;
221 int64_t swap_missed_ust
;
224 GLuint swap_missed_count
;
227 /* These are functions now:
229 void LOCK_HARDWARE( struct intel_context
*intel
);
230 void UNLOCK_HARDWARE( struct intel_context
*intel
);
233 #define SUBPIXEL_X 0.125
234 #define SUBPIXEL_Y 0.125
236 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
238 /* ================================================================
242 #define INTEL_PACKCOLOR4444(r,g,b,a) \
243 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
245 #define INTEL_PACKCOLOR1555(r,g,b,a) \
246 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
249 #define INTEL_PACKCOLOR565(r,g,b) \
250 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
252 #define INTEL_PACKCOLOR8888(r,g,b,a) \
253 ((a<<24) | (r<<16) | (g<<8) | b)
256 #define INTEL_PACKCOLOR(format, r, g, b, a) \
257 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
258 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
259 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
264 /* ================================================================
265 * From linux kernel i386 header files, copes with odd sizes better
266 * than COPY_DWORDS would:
268 #if defined(i386) || defined(__i386__)
269 static inline void * __memcpy(void * to
, const void * from
, size_t n
)
272 __asm__
__volatile__(
277 "1:\ttestb $1,%b4\n\t"
281 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
282 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
287 #define __memcpy(a,b,c) memcpy(a,b,c)
291 /* ================================================================
294 extern int INTEL_DEBUG
;
296 #define DEBUG_TEXTURE 0x1
297 #define DEBUG_STATE 0x2
298 #define DEBUG_IOCTL 0x4
299 #define DEBUG_PRIMS 0x8
300 #define DEBUG_VERTS 0x10
301 #define DEBUG_FALLBACKS 0x20
302 #define DEBUG_VERBOSE 0x40
303 #define DEBUG_DRI 0x80
304 #define DEBUG_DMA 0x100
305 #define DEBUG_SANITY 0x200
306 #define DEBUG_SYNC 0x400
307 #define DEBUG_SLEEP 0x800
308 #define DEBUG_PIXEL 0x1000
309 #define DEBUG_STATS 0x2000
310 #define DEBUG_TILE 0x4000
311 #define DEBUG_SINGLE_THREAD 0x8000
312 #define DEBUG_WM 0x10000
313 #define DEBUG_URB 0x20000
314 #define DEBUG_VS 0x40000
315 #define DEBUG_BATCH 0x80000
316 #define DEBUG_BUFMGR 0x100000
317 #define DEBUG_BLIT 0x200000
318 #define DEBUG_REGION 0x400000
319 #define DEBUG_MIPTREE 0x800000
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
;