Add Intel i965G/Q DRI driver.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.h
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef INTELCONTEXT_INC
29 #define INTELCONTEXT_INC
30
31
32
33 #include "mtypes.h"
34 #include "drm.h"
35 #include "texmem.h"
36
37 #include "intel_screen.h"
38 #include "i830_common.h"
39 #include "tnl/t_vertex.h"
40
41 #define TAG(x) intel##x
42 #include "tnl_dd/t_dd_vertex.h"
43 #undef TAG
44
45 #define DV_PF_555 (1<<8)
46 #define DV_PF_565 (2<<8)
47 #define DV_PF_8888 (3<<8)
48
49 struct intel_region;
50 struct intel_context;
51
52 typedef void (*intel_tri_func)(struct intel_context *, intelVertex *, intelVertex *,
53 intelVertex *);
54 typedef void (*intel_line_func)(struct intel_context *, intelVertex *, intelVertex *);
55 typedef void (*intel_point_func)(struct intel_context *, intelVertex *);
56
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
62
63 extern void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode );
64 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
65
66
67
68 struct intel_texture_object
69 {
70 struct gl_texture_object base; /* The "parent" object */
71
72 /* The mipmap tree must include at least these levels once
73 * validated:
74 */
75 GLuint firstLevel;
76 GLuint lastLevel;
77
78 GLuint dirty_images[6];
79 GLuint dirty;
80
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.
83 */
84 struct intel_mipmap_tree *mt;
85 };
86
87
88
89
90 struct intel_context
91 {
92 GLcontext ctx; /* the parent class */
93
94 struct {
95 void (*destroy)( struct intel_context *intel );
96 void (*emit_state)( struct intel_context *intel );
97 void (*emit_invarient_state)( struct intel_context *intel );
98 void (*lost_hardware)( struct intel_context *intel );
99 void (*note_fence)( struct intel_context *intel, GLuint fence );
100 void (*note_unlock)( struct intel_context *intel );
101 void (*update_texture_state)( struct intel_context *intel );
102
103 void (*render_start)( struct intel_context *intel );
104 void (*set_draw_region)( struct intel_context *intel,
105 struct intel_region *draw_region,
106 struct intel_region *depth_region );
107
108 GLuint (*flush_cmd)( void );
109
110 void (*emit_flush)( struct intel_context *intel,
111 GLuint unused );
112
113 void (*aub_commands)( struct intel_context *intel,
114 GLuint offset,
115 const void *buf,
116 GLuint sz );
117 void (*aub_dump_bmp)( struct intel_context *intel, GLuint buffer );
118 void (*aub_wrap)( struct intel_context *intel );
119 void (*aub_gtt_data)( struct intel_context *intel,
120 GLuint offset,
121 const void *src,
122 GLuint size,
123 GLuint aubtype,
124 GLuint aubsubtype);
125
126
127 void (*reduced_primitive_state)( struct intel_context *intel, GLenum rprim );
128
129 GLboolean (*check_vertex_size)( struct intel_context *intel, GLuint expected );
130
131 void (*invalidate_state)( struct intel_context *intel, GLuint new_state );
132
133 /* Metaops:
134 */
135 void (*install_meta_state)( struct intel_context *intel );
136 void (*leave_meta_state)( struct intel_context *intel );
137
138 void (*meta_draw_region)( struct intel_context *intel,
139 struct intel_region *draw_region,
140 struct intel_region *depth_region );
141
142 void (*meta_color_mask)( struct intel_context *intel,
143 GLboolean );
144
145 void (*meta_stencil_replace)( struct intel_context *intel,
146 GLuint mask,
147 GLuint clear );
148
149 void (*meta_depth_replace)( struct intel_context *intel );
150
151 void (*meta_no_stencil_write)( struct intel_context *intel );
152 void (*meta_no_depth_write)( struct intel_context *intel );
153 void (*meta_no_texture)( struct intel_context *intel );
154
155 void (*meta_draw_quad)(struct intel_context *intel,
156 GLfloat x0, GLfloat x1,
157 GLfloat y0, GLfloat y1,
158 GLfloat z,
159 GLubyte red, GLubyte green,
160 GLubyte blue, GLubyte alpha,
161 GLfloat s0, GLfloat s1,
162 GLfloat t0, GLfloat t1);
163
164
165
166 } vtbl;
167
168 GLint refcount;
169 GLuint Fallback;
170 GLuint NewGLState;
171
172 GLuint last_swap_fence;
173 GLuint second_last_swap_fence;
174
175 GLboolean aub_wrap;
176
177 GLboolean flushBeforeFallback;
178
179 struct intel_batchbuffer *batch;
180
181 struct {
182 GLuint id;
183 GLuint primitive;
184 GLubyte *start_ptr;
185 void (*flush)( struct intel_context * );
186 } prim;
187
188 GLboolean locked;
189 GLboolean strict_conformance;
190
191 GLubyte clear_chan[4];
192 GLuint ClearColor;
193 GLuint ClearDepth;
194
195 /* Offsets of fields within the current vertex:
196 */
197 GLuint coloroffset;
198 GLuint specoffset;
199 GLuint wpos_offset;
200 GLuint wpos_size;
201
202 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
203 GLuint vertex_attr_count;
204
205 GLfloat depth_scale;
206 GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
207 GLuint depth_clear_mask;
208 GLuint stencil_clear_mask;
209
210 GLboolean hw_stencil;
211 GLboolean hw_stipple;
212 GLboolean depth_buffer_is_float;
213 GLboolean perf_boxes;
214 GLboolean no_hw;
215 GLboolean no_rast;
216 GLboolean thrashing;
217
218
219 /* AGP memory buffer manager:
220 */
221 struct bufmgr *bm;
222
223
224 /* State for intelvb.c and inteltris.c.
225 */
226 GLuint RenderIndex;
227 GLmatrix ViewportMatrix;
228 GLenum render_primitive;
229 GLenum reduced_primitive;
230 GLuint vertex_size;
231 GLubyte *verts; /* points to tnl->clipspace.vertex_buf */
232
233
234 struct intel_region *front_region;
235 struct intel_region *back_region;
236 struct intel_region *draw_region;
237 struct intel_region *depth_region;
238
239
240 /* Fallback rasterization functions
241 */
242 intel_point_func draw_point;
243 intel_line_func draw_line;
244 intel_tri_func draw_tri;
245
246 /* These refer to the current draw (front vs. back) buffer:
247 */
248 int drawX; /* origin of drawable in draw buffer */
249 int drawY;
250 GLuint numClipRects; /* cliprects for that buffer */
251 drm_clip_rect_t *pClipRects;
252
253 GLboolean scissor;
254 drm_clip_rect_t draw_rect;
255 drm_clip_rect_t scissor_rect;
256
257 drm_context_t hHWContext;
258 drmLock *driHwLock;
259 int driFd;
260
261 __DRIdrawablePrivate *driDrawable;
262 __DRIscreenPrivate *driScreen;
263 intelScreenPrivate *intelScreen;
264 volatile drmI830Sarea *sarea;
265
266 FILE *aub_file;
267
268 GLuint lastStamp;
269
270 /**
271 * Configuration cache
272 */
273 driOptionCache optionCache;
274
275 /* VBI
276 */
277 GLuint vbl_seq;
278 GLuint vblank_flags;
279
280 int64_t swap_ust;
281 int64_t swap_missed_ust;
282
283 GLuint swap_count;
284 GLuint swap_missed_count;
285 };
286
287 /* These are functions now:
288 */
289 void LOCK_HARDWARE( struct intel_context *intel );
290 void UNLOCK_HARDWARE( struct intel_context *intel );
291
292
293 #define SUBPIXEL_X 0.125
294 #define SUBPIXEL_Y 0.125
295
296 /* ================================================================
297 * Color packing:
298 */
299
300 #define INTEL_PACKCOLOR4444(r,g,b,a) \
301 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
302
303 #define INTEL_PACKCOLOR1555(r,g,b,a) \
304 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
305 ((a) ? 0x8000 : 0))
306
307 #define INTEL_PACKCOLOR565(r,g,b) \
308 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
309
310 #define INTEL_PACKCOLOR8888(r,g,b,a) \
311 ((a<<24) | (r<<16) | (g<<8) | b)
312
313
314 #define INTEL_PACKCOLOR(format, r, g, b, a) \
315 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
316 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
317 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
318 0)))
319
320
321
322 /* ================================================================
323 * From linux kernel i386 header files, copes with odd sizes better
324 * than COPY_DWORDS would:
325 */
326 #if defined(i386) || defined(__i386__)
327 static inline void * __memcpy(void * to, const void * from, size_t n)
328 {
329 int d0, d1, d2;
330 __asm__ __volatile__(
331 "rep ; movsl\n\t"
332 "testb $2,%b4\n\t"
333 "je 1f\n\t"
334 "movsw\n"
335 "1:\ttestb $1,%b4\n\t"
336 "je 2f\n\t"
337 "movsb\n"
338 "2:"
339 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
340 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
341 : "memory");
342 return (to);
343 }
344 #else
345 #define __memcpy(a,b,c) memcpy(a,b,c)
346 #endif
347
348
349 /* The system memcpy (at least on ubuntu 5.10) has problems copying
350 * to agp (writecombined) memory from a source which isn't 64-byte
351 * aligned - there is a 4x performance falloff.
352 *
353 * The x86 __memcpy is immune to this but is slightly slower
354 * (10%-ish) than the system memcpy.
355 *
356 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
357 * isn't much faster than x86_memcpy for agp copies.
358 *
359 * TODO: switch dynamically.
360 */
361 static inline void *do_memcpy( void *dest, const void *src, size_t n )
362 {
363 if ( (((unsigned)src) & 63) ||
364 (((unsigned)dest) & 63)) {
365 return __memcpy(dest, src, n);
366 }
367 else
368 return memcpy(dest, src, n);
369 }
370
371
372
373
374
375 /* ================================================================
376 * Debugging:
377 */
378 extern int INTEL_DEBUG;
379
380 #define DEBUG_TEXTURE 0x1
381 #define DEBUG_STATE 0x2
382 #define DEBUG_IOCTL 0x4
383 #define DEBUG_PRIMS 0x8
384 #define DEBUG_VERTS 0x10
385 #define DEBUG_FALLBACKS 0x20
386 #define DEBUG_VERBOSE 0x40
387 #define DEBUG_DRI 0x80
388 #define DEBUG_DMA 0x100
389 #define DEBUG_SANITY 0x200
390 #define DEBUG_SYNC 0x400
391 #define DEBUG_SLEEP 0x800
392 #define DEBUG_PIXEL 0x1000
393 #define DEBUG_STATS 0x2000
394 #define DEBUG_TILE 0x4000
395 #define DEBUG_SINGLE_THREAD 0x8000
396 #define DEBUG_WM 0x10000
397 #define DEBUG_URB 0x20000
398
399
400 #define PCI_CHIP_845_G 0x2562
401 #define PCI_CHIP_I830_M 0x3577
402 #define PCI_CHIP_I855_GM 0x3582
403 #define PCI_CHIP_I865_G 0x2572
404 #define PCI_CHIP_I915_G 0x2582
405 #define PCI_CHIP_I915_GM 0x2592
406 #define PCI_CHIP_I945_G 0x2772
407 #define PCI_CHIP_I965_G 0x29A2
408 #define PCI_CHIP_I965_Q 0x2992
409 #define PCI_CHIP_I965_G_1 0x2982
410 #define PCI_CHIP_I946_GZ 0x2972
411
412
413 /* ================================================================
414 * intel_context.c:
415 */
416
417 extern GLboolean intelInitContext( struct intel_context *intel,
418 const __GLcontextModes *mesaVis,
419 __DRIcontextPrivate *driContextPriv,
420 void *sharedContextPrivate,
421 struct dd_function_table *functions );
422
423 extern void intelGetLock(struct intel_context *intel, GLuint flags);
424
425 extern void intelInitState( GLcontext *ctx );
426 extern void intelFinish( GLcontext *ctx );
427 extern void intelFlush( GLcontext *ctx );
428
429 extern void intelInitDriverFunctions( struct dd_function_table *functions );
430
431
432 /* ================================================================
433 * intel_state.c:
434 */
435 extern void intelInitStateFuncs( struct dd_function_table *functions );
436
437 #define COMPAREFUNC_ALWAYS 0
438 #define COMPAREFUNC_NEVER 0x1
439 #define COMPAREFUNC_LESS 0x2
440 #define COMPAREFUNC_EQUAL 0x3
441 #define COMPAREFUNC_LEQUAL 0x4
442 #define COMPAREFUNC_GREATER 0x5
443 #define COMPAREFUNC_NOTEQUAL 0x6
444 #define COMPAREFUNC_GEQUAL 0x7
445
446 #define STENCILOP_KEEP 0
447 #define STENCILOP_ZERO 0x1
448 #define STENCILOP_REPLACE 0x2
449 #define STENCILOP_INCRSAT 0x3
450 #define STENCILOP_DECRSAT 0x4
451 #define STENCILOP_INCR 0x5
452 #define STENCILOP_DECR 0x6
453 #define STENCILOP_INVERT 0x7
454
455 #define LOGICOP_CLEAR 0
456 #define LOGICOP_NOR 0x1
457 #define LOGICOP_AND_INV 0x2
458 #define LOGICOP_COPY_INV 0x3
459 #define LOGICOP_AND_RVRSE 0x4
460 #define LOGICOP_INV 0x5
461 #define LOGICOP_XOR 0x6
462 #define LOGICOP_NAND 0x7
463 #define LOGICOP_AND 0x8
464 #define LOGICOP_EQUIV 0x9
465 #define LOGICOP_NOOP 0xa
466 #define LOGICOP_OR_INV 0xb
467 #define LOGICOP_COPY 0xc
468 #define LOGICOP_OR_RVRSE 0xd
469 #define LOGICOP_OR 0xe
470 #define LOGICOP_SET 0xf
471
472 #define BLENDFACT_ZERO 0x01
473 #define BLENDFACT_ONE 0x02
474 #define BLENDFACT_SRC_COLR 0x03
475 #define BLENDFACT_INV_SRC_COLR 0x04
476 #define BLENDFACT_SRC_ALPHA 0x05
477 #define BLENDFACT_INV_SRC_ALPHA 0x06
478 #define BLENDFACT_DST_ALPHA 0x07
479 #define BLENDFACT_INV_DST_ALPHA 0x08
480 #define BLENDFACT_DST_COLR 0x09
481 #define BLENDFACT_INV_DST_COLR 0x0a
482 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
483 #define BLENDFACT_CONST_COLOR 0x0c
484 #define BLENDFACT_INV_CONST_COLOR 0x0d
485 #define BLENDFACT_CONST_ALPHA 0x0e
486 #define BLENDFACT_INV_CONST_ALPHA 0x0f
487 #define BLENDFACT_MASK 0x0f
488
489
490 extern int intel_translate_compare_func( GLenum func );
491 extern int intel_translate_stencil_op( GLenum op );
492 extern int intel_translate_blend_factor( GLenum factor );
493 extern int intel_translate_logic_op( GLenum opcode );
494
495
496 /* ================================================================
497 * intel_buffers.c:
498 */
499 void intelInitBufferFuncs( struct dd_function_table *functions );
500
501 struct intel_region *intel_readbuf_region( struct intel_context *intel );
502 struct intel_region *intel_drawbuf_region( struct intel_context *intel );
503
504 extern void intelWindowMoved( struct intel_context *intel );
505
506 extern GLboolean intel_intersect_cliprects( drm_clip_rect_t *dest,
507 const drm_clip_rect_t *a,
508 const drm_clip_rect_t *b );
509
510
511
512 #define _NEW_WINDOW_POS 0x40000000
513
514
515 /*======================================================================
516 * Inline conversion functions.
517 * These are better-typed than the macros used previously:
518 */
519 static inline struct intel_context *intel_context( GLcontext *ctx )
520 {
521 return (struct intel_context *)ctx;
522 }
523
524 static inline struct intel_texture_object *intel_texture_object( struct gl_texture_object *obj )
525 {
526 return (struct intel_texture_object *)obj;
527 }
528
529 static inline struct intel_texture_image *intel_texture_image( struct gl_texture_image *img )
530 {
531 return (struct intel_texture_image *)img;
532 }
533
534
535 #endif
536