[965] Move to using shared texture management code.
[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 "intel_tex_obj.h"
39 #include "i830_common.h"
40 #include "tnl/t_vertex.h"
41
42 #define TAG(x) intel##x
43 #include "tnl_dd/t_dd_vertex.h"
44 #undef TAG
45
46 #define DV_PF_555 (1<<8)
47 #define DV_PF_565 (2<<8)
48 #define DV_PF_8888 (3<<8)
49
50 struct intel_region;
51 struct intel_context;
52
53 typedef void (*intel_tri_func)(struct intel_context *, intelVertex *, intelVertex *,
54 intelVertex *);
55 typedef void (*intel_line_func)(struct intel_context *, intelVertex *, intelVertex *);
56 typedef void (*intel_point_func)(struct intel_context *, intelVertex *);
57
58 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
59 #define INTEL_FALLBACK_READ_BUFFER 0x2
60 #define INTEL_FALLBACK_USER 0x4
61 #define INTEL_FALLBACK_RENDERMODE 0x8
62 #define INTEL_FALLBACK_TEXTURE 0x10
63
64 extern void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode );
65 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
66
67 #define INTEL_WRITE_PART 0x1
68 #define INTEL_WRITE_FULL 0x2
69 #define INTEL_READ 0x4
70
71 struct intel_context
72 {
73 GLcontext ctx; /* the parent class */
74
75 struct {
76 void (*destroy)( struct intel_context *intel );
77 void (*emit_state)( struct intel_context *intel );
78 void (*emit_invarient_state)( struct intel_context *intel );
79 void (*lost_hardware)( struct intel_context *intel );
80 void (*note_fence)( struct intel_context *intel, GLuint fence );
81 void (*note_unlock)( struct intel_context *intel );
82 void (*update_texture_state)( struct intel_context *intel );
83
84 void (*render_start)( struct intel_context *intel );
85 void (*set_draw_region)( struct intel_context *intel,
86 struct intel_region *draw_region,
87 struct intel_region *depth_region );
88
89 GLuint (*flush_cmd)( void );
90
91 void (*emit_flush)( struct intel_context *intel,
92 GLuint unused );
93
94 void (*reduced_primitive_state)( struct intel_context *intel, GLenum rprim );
95
96 GLboolean (*check_vertex_size)( struct intel_context *intel, GLuint expected );
97
98 void (*invalidate_state)( struct intel_context *intel, GLuint new_state );
99
100 /* Metaops:
101 */
102 void (*install_meta_state)( struct intel_context *intel );
103 void (*leave_meta_state)( struct intel_context *intel );
104
105 void (*meta_draw_region)( struct intel_context *intel,
106 struct intel_region *draw_region,
107 struct intel_region *depth_region );
108
109 void (*meta_color_mask)( struct intel_context *intel,
110 GLboolean );
111
112 void (*meta_stencil_replace)( struct intel_context *intel,
113 GLuint mask,
114 GLuint clear );
115
116 void (*meta_depth_replace)( struct intel_context *intel );
117
118 void (*meta_texture_blend_replace) (struct intel_context * intel);
119
120 void (*meta_no_stencil_write)( struct intel_context *intel );
121 void (*meta_no_depth_write)( struct intel_context *intel );
122 void (*meta_no_texture)( struct intel_context *intel );
123 void (*meta_import_pixel_state) (struct intel_context * intel);
124 void (*meta_frame_buffer_texture)( struct intel_context *intel,
125 GLint xoff, GLint yoff );
126
127 void (*meta_draw_quad)(struct intel_context *intel,
128 GLfloat x0, GLfloat x1,
129 GLfloat y0, GLfloat y1,
130 GLfloat z,
131 GLubyte red, GLubyte green,
132 GLubyte blue, GLubyte alpha,
133 GLfloat s0, GLfloat s1,
134 GLfloat t0, GLfloat t1);
135
136 void (*debug_batch)(struct intel_context *intel);
137 } vtbl;
138
139 GLint refcount;
140 GLuint Fallback;
141 GLuint NewGLState;
142
143 dri_bufmgr *bufmgr;
144 unsigned int maxBatchSize;
145
146 struct intel_region *front_region;
147 struct intel_region *back_region;
148 struct intel_region *third_region;
149 struct intel_region *depth_region;
150
151 /**
152 * This value indicates that the kernel memory manager is being used
153 * instead of the fake client-side memory manager.
154 */
155 GLboolean ttm;
156
157 dri_fence *first_swap_fence;
158 dri_fence *last_swap_fence;
159
160 GLuint stats_wm;
161
162 struct intel_batchbuffer *batch;
163 unsigned batch_id;
164
165 GLubyte clear_chan[4];
166 GLuint ClearColor;
167 GLuint ClearDepth;
168
169 GLfloat depth_scale;
170 GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
171 GLuint depth_clear_mask;
172 GLuint stencil_clear_mask;
173
174 GLboolean hw_stencil;
175 GLboolean hw_stipple;
176 GLboolean depth_buffer_is_float;
177 GLboolean no_rast;
178 GLboolean locked;
179 GLboolean strict_conformance;
180 GLboolean need_flush;
181
182 /* State for intelvb.c and inteltris.c.
183 */
184 GLenum render_primitive;
185 GLenum reduced_primitive;
186
187 struct intel_region *draw_region;
188
189 /* These refer to the current draw (front vs. back) buffer:
190 */
191 int drawX; /* origin of drawable in draw buffer */
192 int drawY;
193 GLuint numClipRects; /* cliprects for that buffer */
194 drm_clip_rect_t *pClipRects;
195 struct gl_texture_object *frame_buffer_texobj;
196
197 GLboolean scissor;
198 drm_clip_rect_t draw_rect;
199 drm_clip_rect_t scissor_rect;
200
201 drm_context_t hHWContext;
202 drmLock *driHwLock;
203 int driFd;
204
205 __DRIdrawablePrivate *driDrawable;
206 __DRIdrawablePrivate *driReadDrawable;
207 __DRIscreenPrivate *driScreen;
208 intelScreenPrivate *intelScreen;
209 volatile drmI830Sarea *sarea;
210
211 GLuint lastStamp;
212
213 GLboolean no_hw;
214
215 /**
216 * Configuration cache
217 */
218 driOptionCache optionCache;
219
220 int64_t swap_ust;
221 int64_t swap_missed_ust;
222
223 GLuint swap_count;
224 GLuint swap_missed_count;
225 };
226
227 /* These are functions now:
228 */
229 void LOCK_HARDWARE( struct intel_context *intel );
230 void UNLOCK_HARDWARE( struct intel_context *intel );
231
232
233 #define SUBPIXEL_X 0.125
234 #define SUBPIXEL_Y 0.125
235
236 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
237
238 /* ================================================================
239 * Color packing:
240 */
241
242 #define INTEL_PACKCOLOR4444(r,g,b,a) \
243 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
244
245 #define INTEL_PACKCOLOR1555(r,g,b,a) \
246 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
247 ((a) ? 0x8000 : 0))
248
249 #define INTEL_PACKCOLOR565(r,g,b) \
250 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
251
252 #define INTEL_PACKCOLOR8888(r,g,b,a) \
253 ((a<<24) | (r<<16) | (g<<8) | b)
254
255
256 #define INTEL_PACKCOLOR(format, r, g, b, a) \
257 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
258 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
259 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
260 0)))
261
262
263
264 /* ================================================================
265 * From linux kernel i386 header files, copes with odd sizes better
266 * than COPY_DWORDS would:
267 */
268 #if defined(i386) || defined(__i386__)
269 static inline void * __memcpy(void * to, const void * from, size_t n)
270 {
271 int d0, d1, d2;
272 __asm__ __volatile__(
273 "rep ; movsl\n\t"
274 "testb $2,%b4\n\t"
275 "je 1f\n\t"
276 "movsw\n"
277 "1:\ttestb $1,%b4\n\t"
278 "je 2f\n\t"
279 "movsb\n"
280 "2:"
281 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
282 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
283 : "memory");
284 return (to);
285 }
286 #else
287 #define __memcpy(a,b,c) memcpy(a,b,c)
288 #endif
289
290
291 /* ================================================================
292 * Debugging:
293 */
294 extern int INTEL_DEBUG;
295
296 #define DEBUG_TEXTURE 0x1
297 #define DEBUG_STATE 0x2
298 #define DEBUG_IOCTL 0x4
299 #define DEBUG_PRIMS 0x8
300 #define DEBUG_VERTS 0x10
301 #define DEBUG_FALLBACKS 0x20
302 #define DEBUG_VERBOSE 0x40
303 #define DEBUG_DRI 0x80
304 #define DEBUG_DMA 0x100
305 #define DEBUG_SANITY 0x200
306 #define DEBUG_SYNC 0x400
307 #define DEBUG_SLEEP 0x800
308 #define DEBUG_PIXEL 0x1000
309 #define DEBUG_STATS 0x2000
310 #define DEBUG_TILE 0x4000
311 #define DEBUG_SINGLE_THREAD 0x8000
312 #define DEBUG_WM 0x10000
313 #define DEBUG_URB 0x20000
314 #define DEBUG_VS 0x40000
315 #define DEBUG_BATCH 0x80000
316 #define DEBUG_BUFMGR 0x100000
317 #define DEBUG_BLIT 0x200000
318 #define DEBUG_REGION 0x400000
319 #define DEBUG_MIPTREE 0x800000
320
321 #define DBG(...) do { \
322 if (INTEL_DEBUG & FILE_DEBUG_FLAG) \
323 _mesa_printf(__VA_ARGS__); \
324 } while(0)
325
326 /* ================================================================
327 * intel_context.c:
328 */
329
330 extern GLboolean intelInitContext( struct intel_context *intel,
331 const __GLcontextModes *mesaVis,
332 __DRIcontextPrivate *driContextPriv,
333 void *sharedContextPrivate,
334 struct dd_function_table *functions );
335
336 extern void intelGetLock(struct intel_context *intel, GLuint flags);
337
338 extern void intelFinish( GLcontext *ctx );
339 extern void intelFlush( GLcontext *ctx );
340
341 extern void intelInitDriverFunctions( struct dd_function_table *functions );
342
343
344 /* ================================================================
345 * intel_state.c:
346 */
347 extern void intelInitStateFuncs( struct dd_function_table *functions );
348
349 #define COMPAREFUNC_ALWAYS 0
350 #define COMPAREFUNC_NEVER 0x1
351 #define COMPAREFUNC_LESS 0x2
352 #define COMPAREFUNC_EQUAL 0x3
353 #define COMPAREFUNC_LEQUAL 0x4
354 #define COMPAREFUNC_GREATER 0x5
355 #define COMPAREFUNC_NOTEQUAL 0x6
356 #define COMPAREFUNC_GEQUAL 0x7
357
358 #define STENCILOP_KEEP 0
359 #define STENCILOP_ZERO 0x1
360 #define STENCILOP_REPLACE 0x2
361 #define STENCILOP_INCRSAT 0x3
362 #define STENCILOP_DECRSAT 0x4
363 #define STENCILOP_INCR 0x5
364 #define STENCILOP_DECR 0x6
365 #define STENCILOP_INVERT 0x7
366
367 #define LOGICOP_CLEAR 0
368 #define LOGICOP_NOR 0x1
369 #define LOGICOP_AND_INV 0x2
370 #define LOGICOP_COPY_INV 0x3
371 #define LOGICOP_AND_RVRSE 0x4
372 #define LOGICOP_INV 0x5
373 #define LOGICOP_XOR 0x6
374 #define LOGICOP_NAND 0x7
375 #define LOGICOP_AND 0x8
376 #define LOGICOP_EQUIV 0x9
377 #define LOGICOP_NOOP 0xa
378 #define LOGICOP_OR_INV 0xb
379 #define LOGICOP_COPY 0xc
380 #define LOGICOP_OR_RVRSE 0xd
381 #define LOGICOP_OR 0xe
382 #define LOGICOP_SET 0xf
383
384 #define BLENDFACT_ZERO 0x01
385 #define BLENDFACT_ONE 0x02
386 #define BLENDFACT_SRC_COLR 0x03
387 #define BLENDFACT_INV_SRC_COLR 0x04
388 #define BLENDFACT_SRC_ALPHA 0x05
389 #define BLENDFACT_INV_SRC_ALPHA 0x06
390 #define BLENDFACT_DST_ALPHA 0x07
391 #define BLENDFACT_INV_DST_ALPHA 0x08
392 #define BLENDFACT_DST_COLR 0x09
393 #define BLENDFACT_INV_DST_COLR 0x0a
394 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
395 #define BLENDFACT_CONST_COLOR 0x0c
396 #define BLENDFACT_INV_CONST_COLOR 0x0d
397 #define BLENDFACT_CONST_ALPHA 0x0e
398 #define BLENDFACT_INV_CONST_ALPHA 0x0f
399 #define BLENDFACT_MASK 0x0f
400
401 extern int intel_translate_shadow_compare_func( GLenum func );
402 extern int intel_translate_compare_func( GLenum func );
403 extern int intel_translate_stencil_op( GLenum op );
404 extern int intel_translate_blend_factor( GLenum factor );
405 extern int intel_translate_logic_op( GLenum opcode );
406
407
408 /* ================================================================
409 * intel_buffers.c:
410 */
411 void intelInitBufferFuncs( struct dd_function_table *functions );
412
413 struct intel_region *intel_readbuf_region( struct intel_context *intel );
414 struct intel_region *intel_drawbuf_region( struct intel_context *intel );
415
416 extern void intelWindowMoved( struct intel_context *intel );
417
418 extern GLboolean intel_intersect_cliprects( drm_clip_rect_t *dest,
419 const drm_clip_rect_t *a,
420 const drm_clip_rect_t *b );
421
422
423 /* ================================================================
424 * intel_pixel_copy.c:
425 */
426 void intelCopyPixels(GLcontext * ctx,
427 GLint srcx, GLint srcy,
428 GLsizei width, GLsizei height,
429 GLint destx, GLint desty, GLenum type);
430
431 GLboolean intel_check_blit_fragment_ops(GLcontext * ctx);
432
433 void intelBitmap(GLcontext * ctx,
434 GLint x, GLint y,
435 GLsizei width, GLsizei height,
436 const struct gl_pixelstore_attrib *unpack,
437 const GLubyte * pixels);
438
439 void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging);
440 #define _NEW_WINDOW_POS 0x40000000
441
442
443 /*======================================================================
444 * Inline conversion functions.
445 * These are better-typed than the macros used previously:
446 */
447 static inline struct intel_context *intel_context( GLcontext *ctx )
448 {
449 return (struct intel_context *)ctx;
450 }
451
452 #endif
453