i965: translate shadow compare function into correct
[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 struct intel_context
90 {
91 GLcontext ctx; /* the parent class */
92
93 struct {
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 );
101
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 );
106
107 GLuint (*flush_cmd)( void );
108
109 void (*emit_flush)( struct intel_context *intel,
110 GLuint unused );
111
112 void (*aub_commands)( struct intel_context *intel,
113 GLuint offset,
114 const void *buf,
115 GLuint sz );
116 void (*aub_dump_bmp)( struct intel_context *intel, GLuint buffer );
117 void (*aub_wrap)( struct intel_context *intel );
118 void (*aub_gtt_data)( struct intel_context *intel,
119 GLuint offset,
120 const void *src,
121 GLuint size,
122 GLuint aubtype,
123 GLuint aubsubtype);
124
125
126 void (*reduced_primitive_state)( struct intel_context *intel, GLenum rprim );
127
128 GLboolean (*check_vertex_size)( struct intel_context *intel, GLuint expected );
129
130 void (*invalidate_state)( struct intel_context *intel, GLuint new_state );
131
132 /* Metaops:
133 */
134 void (*install_meta_state)( struct intel_context *intel );
135 void (*leave_meta_state)( struct intel_context *intel );
136
137 void (*meta_draw_region)( struct intel_context *intel,
138 struct intel_region *draw_region,
139 struct intel_region *depth_region );
140
141 void (*meta_color_mask)( struct intel_context *intel,
142 GLboolean );
143
144 void (*meta_stencil_replace)( struct intel_context *intel,
145 GLuint mask,
146 GLuint clear );
147
148 void (*meta_depth_replace)( struct intel_context *intel );
149
150 void (*meta_texture_blend_replace) (struct intel_context * intel);
151
152 void (*meta_no_stencil_write)( struct intel_context *intel );
153 void (*meta_no_depth_write)( struct intel_context *intel );
154 void (*meta_no_texture)( struct intel_context *intel );
155 void (*meta_import_pixel_state) (struct intel_context * intel);
156 void (*meta_frame_buffer_texture)( struct intel_context *intel,
157 GLint xoff, GLint yoff );
158
159 void (*meta_draw_quad)(struct intel_context *intel,
160 GLfloat x0, GLfloat x1,
161 GLfloat y0, GLfloat y1,
162 GLfloat z,
163 GLubyte red, GLubyte green,
164 GLubyte blue, GLubyte alpha,
165 GLfloat s0, GLfloat s1,
166 GLfloat t0, GLfloat t1);
167
168
169
170 } vtbl;
171
172 GLint refcount;
173 GLuint Fallback;
174 GLuint NewGLState;
175
176 GLuint last_swap_fence;
177 GLuint second_last_swap_fence;
178
179 GLboolean aub_wrap;
180 GLuint stats_wm;
181
182 struct intel_batchbuffer *batch;
183
184 GLubyte clear_chan[4];
185 GLuint ClearColor;
186 GLuint ClearDepth;
187
188 GLfloat depth_scale;
189 GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
190 GLuint depth_clear_mask;
191 GLuint stencil_clear_mask;
192
193 GLboolean hw_stencil;
194 GLboolean hw_stipple;
195 GLboolean depth_buffer_is_float;
196 GLboolean no_hw;
197 GLboolean no_rast;
198 GLboolean thrashing;
199 GLboolean locked;
200 GLboolean strict_conformance;
201 GLboolean need_flush;
202
203
204
205 /* AGP memory buffer manager:
206 */
207 struct bufmgr *bm;
208
209
210 /* State for intelvb.c and inteltris.c.
211 */
212 GLenum render_primitive;
213 GLenum reduced_primitive;
214
215 struct intel_region *front_region;
216 struct intel_region *back_region;
217 struct intel_region *draw_region;
218 struct intel_region *depth_region;
219
220 /* These refer to the current draw (front vs. back) buffer:
221 */
222 int drawX; /* origin of drawable in draw buffer */
223 int drawY;
224 GLuint numClipRects; /* cliprects for that buffer */
225 drm_clip_rect_t *pClipRects;
226 struct gl_texture_object *frame_buffer_texobj;
227
228 GLboolean scissor;
229 drm_clip_rect_t draw_rect;
230 drm_clip_rect_t scissor_rect;
231
232 drm_context_t hHWContext;
233 drmLock *driHwLock;
234 int driFd;
235
236 __DRIdrawablePrivate *driDrawable;
237 __DRIdrawablePrivate *driReadDrawable;
238 __DRIscreenPrivate *driScreen;
239 intelScreenPrivate *intelScreen;
240 volatile drmI830Sarea *sarea;
241
242 FILE *aub_file;
243
244 GLuint lastStamp;
245
246 /**
247 * Configuration cache
248 */
249 driOptionCache optionCache;
250
251 /* VBI
252 */
253 GLuint vbl_seq;
254 GLuint vblank_flags;
255
256 int64_t swap_ust;
257 int64_t swap_missed_ust;
258
259 GLuint swap_count;
260 GLuint swap_missed_count;
261 };
262
263 /* These are functions now:
264 */
265 void LOCK_HARDWARE( struct intel_context *intel );
266 void UNLOCK_HARDWARE( struct intel_context *intel );
267
268
269 #define SUBPIXEL_X 0.125
270 #define SUBPIXEL_Y 0.125
271
272 /* ================================================================
273 * Color packing:
274 */
275
276 #define INTEL_PACKCOLOR4444(r,g,b,a) \
277 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
278
279 #define INTEL_PACKCOLOR1555(r,g,b,a) \
280 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
281 ((a) ? 0x8000 : 0))
282
283 #define INTEL_PACKCOLOR565(r,g,b) \
284 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
285
286 #define INTEL_PACKCOLOR8888(r,g,b,a) \
287 ((a<<24) | (r<<16) | (g<<8) | b)
288
289
290 #define INTEL_PACKCOLOR(format, r, g, b, a) \
291 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
292 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
293 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
294 0)))
295
296
297
298 /* ================================================================
299 * From linux kernel i386 header files, copes with odd sizes better
300 * than COPY_DWORDS would:
301 */
302 #if defined(i386) || defined(__i386__)
303 static inline void * __memcpy(void * to, const void * from, size_t n)
304 {
305 int d0, d1, d2;
306 __asm__ __volatile__(
307 "rep ; movsl\n\t"
308 "testb $2,%b4\n\t"
309 "je 1f\n\t"
310 "movsw\n"
311 "1:\ttestb $1,%b4\n\t"
312 "je 2f\n\t"
313 "movsb\n"
314 "2:"
315 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
316 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
317 : "memory");
318 return (to);
319 }
320 #else
321 #define __memcpy(a,b,c) memcpy(a,b,c)
322 #endif
323
324
325 /* The system memcpy (at least on ubuntu 5.10) has problems copying
326 * to agp (writecombined) memory from a source which isn't 64-byte
327 * aligned - there is a 4x performance falloff.
328 *
329 * The x86 __memcpy is immune to this but is slightly slower
330 * (10%-ish) than the system memcpy.
331 *
332 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
333 * isn't much faster than x86_memcpy for agp copies.
334 *
335 * TODO: switch dynamically.
336 */
337 static inline void *do_memcpy( void *dest, const void *src, size_t n )
338 {
339 if ( (((unsigned long)src) & 63) ||
340 (((unsigned long)dest) & 63)) {
341 return __memcpy(dest, src, n);
342 }
343 else
344 return memcpy(dest, src, n);
345 }
346
347
348
349
350
351 /* ================================================================
352 * Debugging:
353 */
354 extern int INTEL_DEBUG;
355
356 #define DEBUG_TEXTURE 0x1
357 #define DEBUG_STATE 0x2
358 #define DEBUG_IOCTL 0x4
359 #define DEBUG_PRIMS 0x8
360 #define DEBUG_VERTS 0x10
361 #define DEBUG_FALLBACKS 0x20
362 #define DEBUG_VERBOSE 0x40
363 #define DEBUG_DRI 0x80
364 #define DEBUG_DMA 0x100
365 #define DEBUG_SANITY 0x200
366 #define DEBUG_SYNC 0x400
367 #define DEBUG_SLEEP 0x800
368 #define DEBUG_PIXEL 0x1000
369 #define DEBUG_STATS 0x2000
370 #define DEBUG_TILE 0x4000
371 #define DEBUG_SINGLE_THREAD 0x8000
372 #define DEBUG_WM 0x10000
373 #define DEBUG_URB 0x20000
374 #define DEBUG_VS 0x40000
375
376
377 #define PCI_CHIP_845_G 0x2562
378 #define PCI_CHIP_I830_M 0x3577
379 #define PCI_CHIP_I855_GM 0x3582
380 #define PCI_CHIP_I865_G 0x2572
381 #define PCI_CHIP_I915_G 0x2582
382 #define PCI_CHIP_I915_GM 0x2592
383 #define PCI_CHIP_I945_G 0x2772
384 #define PCI_CHIP_I965_G 0x29A2
385 #define PCI_CHIP_I965_Q 0x2992
386 #define PCI_CHIP_I965_G_1 0x2982
387 #define PCI_CHIP_I946_GZ 0x2972
388 #define PCI_CHIP_I965_GM 0x2A02
389 #define PCI_CHIP_I965_GME 0x2A12
390
391
392 /* ================================================================
393 * intel_context.c:
394 */
395
396 extern GLboolean intelInitContext( struct intel_context *intel,
397 const __GLcontextModes *mesaVis,
398 __DRIcontextPrivate *driContextPriv,
399 void *sharedContextPrivate,
400 struct dd_function_table *functions );
401
402 extern void intelGetLock(struct intel_context *intel, GLuint flags);
403
404 extern void intelFinish( GLcontext *ctx );
405 extern void intelFlush( GLcontext *ctx );
406
407 extern void intelInitDriverFunctions( struct dd_function_table *functions );
408
409
410 /* ================================================================
411 * intel_state.c:
412 */
413 extern void intelInitStateFuncs( struct dd_function_table *functions );
414
415 #define COMPAREFUNC_ALWAYS 0
416 #define COMPAREFUNC_NEVER 0x1
417 #define COMPAREFUNC_LESS 0x2
418 #define COMPAREFUNC_EQUAL 0x3
419 #define COMPAREFUNC_LEQUAL 0x4
420 #define COMPAREFUNC_GREATER 0x5
421 #define COMPAREFUNC_NOTEQUAL 0x6
422 #define COMPAREFUNC_GEQUAL 0x7
423
424 #define STENCILOP_KEEP 0
425 #define STENCILOP_ZERO 0x1
426 #define STENCILOP_REPLACE 0x2
427 #define STENCILOP_INCRSAT 0x3
428 #define STENCILOP_DECRSAT 0x4
429 #define STENCILOP_INCR 0x5
430 #define STENCILOP_DECR 0x6
431 #define STENCILOP_INVERT 0x7
432
433 #define LOGICOP_CLEAR 0
434 #define LOGICOP_NOR 0x1
435 #define LOGICOP_AND_INV 0x2
436 #define LOGICOP_COPY_INV 0x3
437 #define LOGICOP_AND_RVRSE 0x4
438 #define LOGICOP_INV 0x5
439 #define LOGICOP_XOR 0x6
440 #define LOGICOP_NAND 0x7
441 #define LOGICOP_AND 0x8
442 #define LOGICOP_EQUIV 0x9
443 #define LOGICOP_NOOP 0xa
444 #define LOGICOP_OR_INV 0xb
445 #define LOGICOP_COPY 0xc
446 #define LOGICOP_OR_RVRSE 0xd
447 #define LOGICOP_OR 0xe
448 #define LOGICOP_SET 0xf
449
450 #define BLENDFACT_ZERO 0x01
451 #define BLENDFACT_ONE 0x02
452 #define BLENDFACT_SRC_COLR 0x03
453 #define BLENDFACT_INV_SRC_COLR 0x04
454 #define BLENDFACT_SRC_ALPHA 0x05
455 #define BLENDFACT_INV_SRC_ALPHA 0x06
456 #define BLENDFACT_DST_ALPHA 0x07
457 #define BLENDFACT_INV_DST_ALPHA 0x08
458 #define BLENDFACT_DST_COLR 0x09
459 #define BLENDFACT_INV_DST_COLR 0x0a
460 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
461 #define BLENDFACT_CONST_COLOR 0x0c
462 #define BLENDFACT_INV_CONST_COLOR 0x0d
463 #define BLENDFACT_CONST_ALPHA 0x0e
464 #define BLENDFACT_INV_CONST_ALPHA 0x0f
465 #define BLENDFACT_MASK 0x0f
466
467 extern int intel_translate_shadow_compare_func( GLenum func );
468 extern int intel_translate_compare_func( GLenum func );
469 extern int intel_translate_stencil_op( GLenum op );
470 extern int intel_translate_blend_factor( GLenum factor );
471 extern int intel_translate_logic_op( GLenum opcode );
472
473
474 /* ================================================================
475 * intel_buffers.c:
476 */
477 void intelInitBufferFuncs( struct dd_function_table *functions );
478
479 struct intel_region *intel_readbuf_region( struct intel_context *intel );
480 struct intel_region *intel_drawbuf_region( struct intel_context *intel );
481
482 extern void intelWindowMoved( struct intel_context *intel );
483
484 extern GLboolean intel_intersect_cliprects( drm_clip_rect_t *dest,
485 const drm_clip_rect_t *a,
486 const drm_clip_rect_t *b );
487
488
489 /* ================================================================
490 * intel_pixel_copy.c:
491 */
492 void intelCopyPixels(GLcontext * ctx,
493 GLint srcx, GLint srcy,
494 GLsizei width, GLsizei height,
495 GLint destx, GLint desty, GLenum type);
496
497 GLboolean intel_check_blit_fragment_ops(GLcontext * ctx);
498
499 void intelBitmap(GLcontext * ctx,
500 GLint x, GLint y,
501 GLsizei width, GLsizei height,
502 const struct gl_pixelstore_attrib *unpack,
503 const GLubyte * pixels);
504
505 void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging);
506 #define _NEW_WINDOW_POS 0x40000000
507
508
509 /*======================================================================
510 * Inline conversion functions.
511 * These are better-typed than the macros used previously:
512 */
513 static inline struct intel_context *intel_context( GLcontext *ctx )
514 {
515 return (struct intel_context *)ctx;
516 }
517
518 static inline struct intel_texture_object *intel_texture_object( struct gl_texture_object *obj )
519 {
520 return (struct intel_texture_object *)obj;
521 }
522
523 static inline struct intel_texture_image *intel_texture_image( struct gl_texture_image *img )
524 {
525 return (struct intel_texture_image *)img;
526 }
527
528 #endif
529