[intel] Remove the dead intel->need_flush member.
[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 #include "dri_bufmgr.h"
37
38 #include "intel_screen.h"
39 #include "intel_tex_obj.h"
40 #include "i830_common.h"
41 #include "tnl/t_vertex.h"
42
43 #define TAG(x) intel##x
44 #include "tnl_dd/t_dd_vertex.h"
45 #undef TAG
46
47 #define DV_PF_555 (1<<8)
48 #define DV_PF_565 (2<<8)
49 #define DV_PF_8888 (3<<8)
50
51 struct intel_region;
52 struct intel_context;
53
54 typedef void (*intel_tri_func)(struct intel_context *, intelVertex *, intelVertex *,
55 intelVertex *);
56 typedef void (*intel_line_func)(struct intel_context *, intelVertex *, intelVertex *);
57 typedef void (*intel_point_func)(struct intel_context *, intelVertex *);
58
59 #define INTEL_FALLBACK_DRAW_BUFFER 0x1
60 #define INTEL_FALLBACK_READ_BUFFER 0x2
61 #define INTEL_FALLBACK_USER 0x4
62 #define INTEL_FALLBACK_RENDERMODE 0x8
63 #define INTEL_FALLBACK_TEXTURE 0x10
64 #define INTEL_FALLBACK_DEPTH_BUFFER 0x20
65 #define INTEL_FALLBACK_STENCIL_BUFFER 0x40
66
67 extern void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode );
68 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
69
70 #define INTEL_WRITE_PART 0x1
71 #define INTEL_WRITE_FULL 0x2
72 #define INTEL_READ 0x4
73
74 struct intel_context
75 {
76 GLcontext ctx; /* the parent class */
77
78 struct {
79 void (*destroy)( struct intel_context *intel );
80 void (*emit_state)( struct intel_context *intel );
81 void (*emit_invarient_state)( struct intel_context *intel );
82 void (*lost_hardware)( struct intel_context *intel );
83 void (*note_fence)( struct intel_context *intel, GLuint fence );
84 void (*note_unlock)( struct intel_context *intel );
85 void (*update_texture_state)( struct intel_context *intel );
86
87 void (*render_start)( struct intel_context *intel );
88 void (*set_draw_region)( struct intel_context *intel,
89 struct intel_region *draw_region,
90 struct intel_region *depth_region );
91
92 GLuint (*flush_cmd)( void );
93
94 void (*emit_flush)( struct intel_context *intel,
95 GLuint unused );
96
97 void (*reduced_primitive_state)( struct intel_context *intel, GLenum rprim );
98
99 GLboolean (*check_vertex_size)( struct intel_context *intel, GLuint expected );
100
101 void (*invalidate_state)( struct intel_context *intel, GLuint new_state );
102
103 /* Metaops:
104 */
105 void (*install_meta_state)( struct intel_context *intel );
106 void (*leave_meta_state)( struct intel_context *intel );
107
108 void (*meta_draw_region)( struct intel_context *intel,
109 struct intel_region *draw_region,
110 struct intel_region *depth_region );
111
112 void (*meta_color_mask)( struct intel_context *intel,
113 GLboolean );
114
115 void (*meta_stencil_replace)( struct intel_context *intel,
116 GLuint mask,
117 GLuint clear );
118
119 void (*meta_depth_replace)( struct intel_context *intel );
120
121 void (*meta_texture_blend_replace) (struct intel_context * intel);
122
123 void (*meta_no_stencil_write)( struct intel_context *intel );
124 void (*meta_no_depth_write)( struct intel_context *intel );
125 void (*meta_no_texture)( struct intel_context *intel );
126 void (*meta_import_pixel_state) (struct intel_context * intel);
127 void (*meta_frame_buffer_texture)( struct intel_context *intel,
128 GLint xoff, GLint yoff );
129
130 void (*meta_draw_quad)(struct intel_context *intel,
131 GLfloat x0, GLfloat x1,
132 GLfloat y0, GLfloat y1,
133 GLfloat z,
134 GLuint color, /* ARGB32 */
135 GLfloat s0, GLfloat s1,
136 GLfloat t0, GLfloat t1);
137
138 void (*debug_batch)(struct intel_context *intel);
139 } vtbl;
140
141 GLint refcount;
142 GLuint Fallback;
143 GLuint NewGLState;
144
145 dri_bufmgr *bufmgr;
146 unsigned int maxBatchSize;
147
148 struct intel_region *front_region;
149 struct intel_region *back_region;
150 struct intel_region *third_region;
151 struct intel_region *depth_region;
152
153 /**
154 * This value indicates that the kernel memory manager is being used
155 * instead of the fake client-side memory manager.
156 */
157 GLboolean ttm;
158
159 dri_fence *first_swap_fence;
160 dri_fence *last_swap_fence;
161
162 GLuint stats_wm;
163
164 struct intel_batchbuffer *batch;
165 unsigned batch_id;
166
167 GLubyte clear_chan[4];
168 GLuint ClearColor565;
169 GLuint ClearColor8888;
170
171 GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
172
173 GLboolean hw_stencil;
174 GLboolean hw_stipple;
175 GLboolean depth_buffer_is_float;
176 GLboolean no_rast;
177 GLboolean locked;
178 GLboolean strict_conformance;
179
180 /* State for intelvb.c and inteltris.c.
181 */
182 GLenum render_primitive;
183 GLenum reduced_primitive;
184
185 struct intel_region *draw_region;
186
187 /* These refer to the current draw (front vs. back) buffer:
188 */
189 int drawX; /* origin of drawable in draw buffer */
190 int drawY;
191 GLuint numClipRects; /* cliprects for that buffer */
192 drm_clip_rect_t *pClipRects;
193 struct gl_texture_object *frame_buffer_texobj;
194 drm_clip_rect_t fboRect; /**< cliprect for FBO rendering */
195
196 GLboolean scissor;
197 drm_clip_rect_t draw_rect;
198 drm_clip_rect_t scissor_rect;
199
200 drm_context_t hHWContext;
201 drmLock *driHwLock;
202 int driFd;
203
204 __DRIdrawablePrivate *driDrawable;
205 __DRIdrawablePrivate *driReadDrawable;
206 __DRIscreenPrivate *driScreen;
207 intelScreenPrivate *intelScreen;
208 volatile drmI830Sarea *sarea;
209
210 GLuint lastStamp;
211
212 GLboolean no_hw;
213
214 /**
215 * Configuration cache
216 */
217 driOptionCache optionCache;
218
219 int64_t swap_ust;
220 int64_t swap_missed_ust;
221
222 GLuint swap_count;
223 GLuint swap_missed_count;
224 };
225
226 /* These are functions now:
227 */
228 void LOCK_HARDWARE( struct intel_context *intel );
229 void UNLOCK_HARDWARE( struct intel_context *intel );
230
231
232 #define SUBPIXEL_X 0.125
233 #define SUBPIXEL_Y 0.125
234
235 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
236
237 /* ================================================================
238 * Color packing:
239 */
240
241 #define INTEL_PACKCOLOR4444(r,g,b,a) \
242 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
243
244 #define INTEL_PACKCOLOR1555(r,g,b,a) \
245 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
246 ((a) ? 0x8000 : 0))
247
248 #define INTEL_PACKCOLOR565(r,g,b) \
249 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
250
251 #define INTEL_PACKCOLOR8888(r,g,b,a) \
252 ((a<<24) | (r<<16) | (g<<8) | b)
253
254
255 #define INTEL_PACKCOLOR(format, r, g, b, a) \
256 (format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) : \
257 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) : \
258 (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) : \
259 0)))
260
261
262
263 /* ================================================================
264 * From linux kernel i386 header files, copes with odd sizes better
265 * than COPY_DWORDS would:
266 */
267 #if defined(i386) || defined(__i386__)
268 static inline void * __memcpy(void * to, const void * from, size_t n)
269 {
270 int d0, d1, d2;
271 __asm__ __volatile__(
272 "rep ; movsl\n\t"
273 "testb $2,%b4\n\t"
274 "je 1f\n\t"
275 "movsw\n"
276 "1:\ttestb $1,%b4\n\t"
277 "je 2f\n\t"
278 "movsb\n"
279 "2:"
280 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
281 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
282 : "memory");
283 return (to);
284 }
285 #else
286 #define __memcpy(a,b,c) memcpy(a,b,c)
287 #endif
288
289
290 /* ================================================================
291 * Debugging:
292 */
293 extern int INTEL_DEBUG;
294
295 #define DEBUG_TEXTURE 0x1
296 #define DEBUG_STATE 0x2
297 #define DEBUG_IOCTL 0x4
298 #define DEBUG_PRIMS 0x8
299 #define DEBUG_VERTS 0x10
300 #define DEBUG_FALLBACKS 0x20
301 #define DEBUG_VERBOSE 0x40
302 #define DEBUG_DRI 0x80
303 #define DEBUG_DMA 0x100
304 #define DEBUG_SANITY 0x200
305 #define DEBUG_SYNC 0x400
306 #define DEBUG_SLEEP 0x800
307 #define DEBUG_PIXEL 0x1000
308 #define DEBUG_STATS 0x2000
309 #define DEBUG_TILE 0x4000
310 #define DEBUG_SINGLE_THREAD 0x8000
311 #define DEBUG_WM 0x10000
312 #define DEBUG_URB 0x20000
313 #define DEBUG_VS 0x40000
314 #define DEBUG_BATCH 0x80000
315 #define DEBUG_BUFMGR 0x100000
316 #define DEBUG_BLIT 0x200000
317 #define DEBUG_REGION 0x400000
318 #define DEBUG_MIPTREE 0x800000
319 #define DEBUG_FBO 0x1000000
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