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