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