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