intel_context.h revision fe91c05b5494b889c8adda77ff562712116d2e59
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 "mm.h"
36#include "texmem.h"
37#include "dri_bufmgr.h"
38
39#include "intel_screen.h"
40#include "intel_tex_obj.h"
41#include "i915_drm.h"
42#include "tnl/t_vertex.h"
43
44#define TAG(x) intel##x
45#include "tnl_dd/t_dd_vertex.h"
46#undef TAG
47
48#define DV_PF_555  (1<<8)
49#define DV_PF_565  (2<<8)
50#define DV_PF_8888 (3<<8)
51
52struct intel_region;
53struct intel_context;
54
55typedef void (*intel_tri_func) (struct intel_context *, intelVertex *,
56                                intelVertex *, intelVertex *);
57typedef void (*intel_line_func) (struct intel_context *, intelVertex *,
58                                 intelVertex *);
59typedef void (*intel_point_func) (struct intel_context *, intelVertex *);
60
61#define INTEL_FALLBACK_DRAW_BUFFER	 0x1
62#define INTEL_FALLBACK_READ_BUFFER	 0x2
63#define INTEL_FALLBACK_DEPTH_BUFFER      0x4
64#define INTEL_FALLBACK_STENCIL_BUFFER    0x8
65#define INTEL_FALLBACK_USER		 0x10
66#define INTEL_FALLBACK_RENDERMODE	 0x20
67#define INTEL_FALLBACK_TEXTURE   	 0x40
68
69extern void intelFallback(struct intel_context *intel, GLuint bit,
70                          GLboolean mode);
71#define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
72
73
74#define INTEL_WRITE_PART  0x1
75#define INTEL_WRITE_FULL  0x2
76#define INTEL_READ        0x4
77
78#define INTEL_MAX_FIXUP 64
79
80struct intel_context
81{
82   GLcontext ctx;               /* the parent class */
83
84   struct
85   {
86      void (*destroy) (struct intel_context * intel);
87      void (*emit_state) (struct intel_context * intel);
88      void (*new_batch) (struct intel_context * intel);
89      void (*emit_invarient_state) (struct intel_context * intel);
90      void (*note_fence) (struct intel_context *intel, GLuint fence);
91      void (*note_unlock) (struct intel_context *intel);
92      void (*update_texture_state) (struct intel_context * intel);
93
94      void (*render_start) (struct intel_context * intel);
95      void (*render_prevalidate) (struct intel_context * intel);
96      void (*set_draw_region) (struct intel_context * intel,
97                               struct intel_region * draw_region,
98                               struct intel_region * depth_region);
99
100      GLuint (*flush_cmd) (void);
101      void (*emit_flush) (struct intel_context *intel, GLuint unused);
102
103      void (*reduced_primitive_state) (struct intel_context * intel,
104                                       GLenum rprim);
105
106      GLboolean (*check_vertex_size) (struct intel_context * intel,
107				      GLuint expected);
108      void (*invalidate_state) (struct intel_context *intel,
109				GLuint new_state);
110
111
112      /* Metaops:
113       */
114      void (*install_meta_state) (struct intel_context * intel);
115      void (*leave_meta_state) (struct intel_context * intel);
116
117      void (*meta_draw_region) (struct intel_context * intel,
118                                struct intel_region * draw_region,
119                                struct intel_region * depth_region);
120
121      void (*meta_draw_quad)(struct intel_context *intel,
122			     GLfloat x0, GLfloat x1,
123			     GLfloat y0, GLfloat y1,
124			     GLfloat z,
125			     GLuint color, /* ARGB32 */
126			     GLfloat s0, GLfloat s1,
127			     GLfloat t0, GLfloat t1);
128
129      void (*meta_color_mask) (struct intel_context * intel, GLboolean);
130
131      void (*meta_stencil_replace) (struct intel_context * intel,
132                                    GLuint mask, 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
142      void (*meta_import_pixel_state) (struct intel_context * intel);
143      void (*meta_frame_buffer_texture) (struct intel_context *intel,
144					 GLint xoff, GLint yoff);
145
146      GLboolean(*meta_tex_rect_source) (struct intel_context * intel,
147					dri_bo * buffer,
148					GLuint offset,
149					GLuint pitch,
150					GLuint height,
151					GLenum format, GLenum type);
152
153      void (*assert_not_dirty) (struct intel_context *intel);
154
155      void (*debug_batch)(struct intel_context *intel);
156   } vtbl;
157
158   GLint refcount;
159   GLuint Fallback;
160   GLuint NewGLState;
161
162   dri_bufmgr *bufmgr;
163   unsigned int maxBatchSize;
164
165   struct intel_region *front_region;
166   struct intel_region *back_region;
167   struct intel_region *third_region;
168   struct intel_region *depth_region;
169
170   /**
171    * This value indicates that the kernel memory manager is being used
172    * instead of the fake client-side memory manager.
173    */
174   GLboolean ttm;
175
176   dri_fence *last_swap_fence;
177   dri_fence *first_swap_fence;
178
179   struct intel_batchbuffer *batch;
180   GLboolean no_batch_wrap;
181   unsigned batch_id;
182
183   struct
184   {
185      GLuint id;
186      GLuint primitive;
187      GLubyte *start_ptr;
188      void (*flush) (struct intel_context *);
189   } prim;
190
191   GLuint stats_wm;
192   GLboolean locked;
193   char *prevLockFile;
194   int prevLockLine;
195
196   GLubyte clear_chan[4];
197   GLuint ClearColor565;
198   GLuint ClearColor8888;
199
200   /* Offsets of fields within the current vertex:
201    */
202   GLuint coloroffset;
203   GLuint specoffset;
204   GLuint wpos_offset;
205   GLuint wpos_size;
206
207   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
208   GLuint vertex_attr_count;
209
210   GLfloat polygon_offset_scale;        /* dependent on depth_scale, bpp */
211
212   GLboolean hw_stencil;
213   GLboolean hw_stipple;
214   GLboolean depth_buffer_is_float;
215   GLboolean no_rast;
216   GLboolean strict_conformance;
217
218   /* State for intelvb.c and inteltris.c.
219    */
220   GLuint RenderIndex;
221   GLmatrix ViewportMatrix;
222   GLenum render_primitive;
223   GLenum reduced_primitive;
224   GLuint vertex_size;
225   GLubyte *verts;              /* points to tnl->clipspace.vertex_buf */
226   struct intel_region *draw_region;
227
228   /* Fallback rasterization functions
229    */
230   intel_point_func draw_point;
231   intel_line_func draw_line;
232   intel_tri_func draw_tri;
233
234   /* These refer to the current drawing buffer:
235    */
236   int drawX, drawY;            /**< origin of drawing area within region */
237   GLuint numClipRects;         /**< cliprects for drawing */
238   drm_clip_rect_t *pClipRects;
239   struct gl_texture_object *frame_buffer_texobj;
240   drm_clip_rect_t fboRect;     /**< cliprect for FBO rendering */
241
242   int perf_boxes;
243
244   GLuint do_usleeps;
245   int do_irqs;
246   GLuint irqsEmitted;
247
248   GLboolean scissor;
249   drm_clip_rect_t draw_rect;
250   drm_clip_rect_t scissor_rect;
251
252   drm_context_t hHWContext;
253   drmLock *driHwLock;
254   int driFd;
255
256   __DRIdrawablePrivate *driDrawable;
257   __DRIdrawablePrivate *driReadDrawable;
258   __DRIscreenPrivate *driScreen;
259   intelScreenPrivate *intelScreen;
260   volatile struct drm_i915_sarea *sarea;
261
262   GLuint lastStamp;
263
264   GLboolean no_hw;
265
266   /**
267    * Configuration cache
268    */
269   driOptionCache optionCache;
270
271   /* Last seen width/height of the screen */
272   int width;
273   int height;
274
275   int64_t swap_ust;
276   int64_t swap_missed_ust;
277
278   GLuint swap_count;
279   GLuint swap_missed_count;
280};
281
282/* These are functions now:
283 */
284void LOCK_HARDWARE( struct intel_context *intel );
285void UNLOCK_HARDWARE( struct intel_context *intel );
286
287extern char *__progname;
288
289
290#define SUBPIXEL_X 0.125
291#define SUBPIXEL_Y 0.125
292
293#define ALIGN(value, alignment)  ((value + alignment - 1) & ~(alignment - 1))
294
295#define INTEL_FIREVERTICES(intel)		\
296do {						\
297   if ((intel)->prim.flush)			\
298      (intel)->prim.flush(intel);		\
299} while (0)
300
301/* ================================================================
302 * Color packing:
303 */
304
305#define INTEL_PACKCOLOR4444(r,g,b,a) \
306  ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
307
308#define INTEL_PACKCOLOR1555(r,g,b,a) \
309  ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
310    ((a) ? 0x8000 : 0))
311
312#define INTEL_PACKCOLOR565(r,g,b) \
313  ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
314
315#define INTEL_PACKCOLOR8888(r,g,b,a) \
316  ((a<<24) | (r<<16) | (g<<8) | b)
317
318#define INTEL_PACKCOLOR(format, r,  g,  b, a)		\
319(format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) :	\
320 (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) :	\
321  (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) :	\
322   0)))
323
324/* ================================================================
325 * From linux kernel i386 header files, copes with odd sizes better
326 * than COPY_DWORDS would:
327 * XXX Put this in src/mesa/main/imports.h ???
328 */
329#if defined(i386) || defined(__i386__)
330static inline void * __memcpy(void * to, const void * from, size_t n)
331{
332   int d0, d1, d2;
333   __asm__ __volatile__(
334      "rep ; movsl\n\t"
335      "testb $2,%b4\n\t"
336      "je 1f\n\t"
337      "movsw\n"
338      "1:\ttestb $1,%b4\n\t"
339      "je 2f\n\t"
340      "movsb\n"
341      "2:"
342      : "=&c" (d0), "=&D" (d1), "=&S" (d2)
343      :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
344      : "memory");
345   return (to);
346}
347#else
348#define __memcpy(a,b,c) memcpy(a,b,c)
349#endif
350
351
352/* ================================================================
353 * Debugging:
354 */
355extern int INTEL_DEBUG;
356
357#define DEBUG_TEXTURE	0x1
358#define DEBUG_STATE	0x2
359#define DEBUG_IOCTL	0x4
360#define DEBUG_BLIT	0x8
361#define DEBUG_MIPTREE   0x10
362#define DEBUG_FALLBACKS	0x20
363#define DEBUG_VERBOSE	0x40
364#define DEBUG_BATCH     0x80
365#define DEBUG_PIXEL     0x100
366#define DEBUG_BUFMGR    0x200
367#define DEBUG_REGION    0x400
368#define DEBUG_FBO       0x800
369#define DEBUG_LOCK      0x1000
370#define DEBUG_SYNC	0x2000
371#define DEBUG_PRIMS	0x4000
372#define DEBUG_VERTS	0x8000
373#define DEBUG_DRI       0x10000
374#define DEBUG_DMA       0x20000
375#define DEBUG_SANITY    0x40000
376#define DEBUG_SLEEP     0x80000
377#define DEBUG_STATS     0x100000
378#define DEBUG_TILE      0x200000
379#define DEBUG_SINGLE_THREAD   0x400000
380#define DEBUG_WM        0x800000
381#define DEBUG_URB       0x1000000
382#define DEBUG_VS        0x2000000
383
384#define DBG(...) do {						\
385	if (INTEL_DEBUG & FILE_DEBUG_FLAG)			\
386		_mesa_printf(__VA_ARGS__);			\
387} while(0)
388
389#define PCI_CHIP_845_G			0x2562
390#define PCI_CHIP_I830_M			0x3577
391#define PCI_CHIP_I855_GM		0x3582
392#define PCI_CHIP_I865_G			0x2572
393#define PCI_CHIP_I915_G			0x2582
394#define PCI_CHIP_I915_GM		0x2592
395#define PCI_CHIP_I945_G			0x2772
396#define PCI_CHIP_I945_GM		0x27A2
397#define PCI_CHIP_I945_GME		0x27AE
398#define PCI_CHIP_G33_G			0x29C2
399#define PCI_CHIP_Q35_G			0x29B2
400#define PCI_CHIP_Q33_G			0x29D2
401
402
403/* ================================================================
404 * intel_context.c:
405 */
406
407extern GLboolean intelInitContext(struct intel_context *intel,
408                                  const __GLcontextModes * mesaVis,
409                                  __DRIcontextPrivate * driContextPriv,
410                                  void *sharedContextPrivate,
411                                  struct dd_function_table *functions);
412
413extern void intelGetLock(struct intel_context *intel, GLuint flags);
414
415extern void intelFinish(GLcontext * ctx);
416extern void intelFlush(GLcontext * ctx);
417
418extern void intelInitDriverFunctions(struct dd_function_table *functions);
419extern void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging);
420
421
422/* ================================================================
423 * intel_state.c:
424 */
425extern void intelInitStateFuncs(struct dd_function_table *functions);
426
427#define COMPAREFUNC_ALWAYS		0
428#define COMPAREFUNC_NEVER		0x1
429#define COMPAREFUNC_LESS		0x2
430#define COMPAREFUNC_EQUAL		0x3
431#define COMPAREFUNC_LEQUAL		0x4
432#define COMPAREFUNC_GREATER		0x5
433#define COMPAREFUNC_NOTEQUAL		0x6
434#define COMPAREFUNC_GEQUAL		0x7
435
436#define STENCILOP_KEEP			0
437#define STENCILOP_ZERO			0x1
438#define STENCILOP_REPLACE		0x2
439#define STENCILOP_INCRSAT		0x3
440#define STENCILOP_DECRSAT		0x4
441#define STENCILOP_INCR			0x5
442#define STENCILOP_DECR			0x6
443#define STENCILOP_INVERT		0x7
444
445#define LOGICOP_CLEAR			0
446#define LOGICOP_NOR			0x1
447#define LOGICOP_AND_INV 		0x2
448#define LOGICOP_COPY_INV		0x3
449#define LOGICOP_AND_RVRSE		0x4
450#define LOGICOP_INV			0x5
451#define LOGICOP_XOR			0x6
452#define LOGICOP_NAND			0x7
453#define LOGICOP_AND			0x8
454#define LOGICOP_EQUIV			0x9
455#define LOGICOP_NOOP			0xa
456#define LOGICOP_OR_INV			0xb
457#define LOGICOP_COPY			0xc
458#define LOGICOP_OR_RVRSE		0xd
459#define LOGICOP_OR			0xe
460#define LOGICOP_SET			0xf
461
462#define BLENDFACT_ZERO			0x01
463#define BLENDFACT_ONE			0x02
464#define BLENDFACT_SRC_COLR		0x03
465#define BLENDFACT_INV_SRC_COLR 		0x04
466#define BLENDFACT_SRC_ALPHA		0x05
467#define BLENDFACT_INV_SRC_ALPHA 	0x06
468#define BLENDFACT_DST_ALPHA		0x07
469#define BLENDFACT_INV_DST_ALPHA 	0x08
470#define BLENDFACT_DST_COLR		0x09
471#define BLENDFACT_INV_DST_COLR		0x0a
472#define BLENDFACT_SRC_ALPHA_SATURATE	0x0b
473#define BLENDFACT_CONST_COLOR		0x0c
474#define BLENDFACT_INV_CONST_COLOR	0x0d
475#define BLENDFACT_CONST_ALPHA		0x0e
476#define BLENDFACT_INV_CONST_ALPHA	0x0f
477#define BLENDFACT_MASK          	0x0f
478
479enum {
480   DRI_CONF_BO_REUSE_DISABLED,
481   DRI_CONF_BO_REUSE_ALL
482};
483
484extern int intel_translate_shadow_compare_func(GLenum func);
485extern int intel_translate_compare_func(GLenum func);
486extern int intel_translate_stencil_op(GLenum op);
487extern int intel_translate_blend_factor(GLenum factor);
488extern int intel_translate_logic_op(GLenum opcode);
489
490
491/*======================================================================
492 * Inline conversion functions.
493 * These are better-typed than the macros used previously:
494 */
495static INLINE struct intel_context *
496intel_context(GLcontext * ctx)
497{
498   return (struct intel_context *) ctx;
499}
500
501#endif
502