Merge branch 'master' of git+ssh://joukj@git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / mesa / drivers / dri / i915 / 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 "mm.h"
36 #include "texmem.h"
37
38 #include "intel_screen.h"
39 #include "intel_tex_obj.h"
40 #include "i915_drm.h"
41 #include "i830_common.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
52 struct intel_region;
53 struct intel_context;
54
55 typedef void (*intel_tri_func) (struct intel_context *, intelVertex *,
56 intelVertex *, intelVertex *);
57 typedef void (*intel_line_func) (struct intel_context *, intelVertex *,
58 intelVertex *);
59 typedef 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
68 extern void intelFallback(struct intel_context *intel, GLuint bit,
69 GLboolean mode);
70 #define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
71
72
73 #define INTEL_WRITE_PART 0x1
74 #define INTEL_WRITE_FULL 0x2
75 #define INTEL_READ 0x4
76
77 #define INTEL_MAX_FIXUP 64
78
79 struct intel_context
80 {
81 GLcontext ctx; /* the parent class */
82
83 struct
84 {
85 void (*destroy) (struct intel_context * intel);
86 void (*emit_state) (struct intel_context * intel);
87 void (*lost_hardware) (struct intel_context * intel);
88 void (*update_texture_state) (struct intel_context * intel);
89
90 void (*render_start) (struct intel_context * intel);
91 void (*render_prevalidate) (struct intel_context * intel);
92 void (*set_draw_region) (struct intel_context * intel,
93 struct intel_region * draw_region,
94 struct intel_region * depth_region);
95
96 GLuint(*flush_cmd) (void);
97
98 void (*reduced_primitive_state) (struct intel_context * intel,
99 GLenum rprim);
100
101 GLboolean(*check_vertex_size) (struct intel_context * intel,
102 GLuint expected);
103
104
105 /* Metaops:
106 */
107 void (*install_meta_state) (struct intel_context * intel);
108 void (*leave_meta_state) (struct intel_context * intel);
109
110 void (*meta_draw_region) (struct intel_context * intel,
111 struct intel_region * draw_region,
112 struct intel_region * depth_region);
113
114 void (*meta_color_mask) (struct intel_context * intel, GLboolean);
115
116 void (*meta_stencil_replace) (struct intel_context * intel,
117 GLuint mask, 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
127 void (*meta_import_pixel_state) (struct intel_context * intel);
128
129 GLboolean(*meta_tex_rect_source) (struct intel_context * intel,
130 dri_bo * buffer,
131 GLuint offset,
132 GLuint pitch,
133 GLuint height,
134 GLenum format, GLenum type);
135
136 void (*assert_not_dirty) (struct intel_context *intel);
137
138 } vtbl;
139
140 GLint refcount;
141 GLuint Fallback;
142 GLuint NewGLState;
143
144 dri_fence *last_swap_fence;
145 dri_fence *first_swap_fence;
146
147 struct intel_batchbuffer *batch;
148 GLuint last_state_batch_id;
149
150 struct
151 {
152 GLuint id;
153 GLuint primitive;
154 GLubyte *start_ptr;
155 void (*flush) (struct intel_context *);
156 } prim;
157
158 GLboolean locked;
159 char *prevLockFile;
160 int prevLockLine;
161
162 GLuint ClearColor565;
163 GLuint ClearColor8888;
164
165 /* Offsets of fields within the current vertex:
166 */
167 GLuint coloroffset;
168 GLuint specoffset;
169 GLuint wpos_offset;
170 GLuint wpos_size;
171
172 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
173 GLuint vertex_attr_count;
174
175 GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
176
177 GLboolean hw_stipple;
178 GLboolean strict_conformance;
179
180 /* State for intelvb.c and inteltris.c.
181 */
182 GLuint RenderIndex;
183 GLmatrix ViewportMatrix;
184 GLenum render_primitive;
185 GLenum reduced_primitive;
186 GLuint vertex_size;
187 GLubyte *verts; /* points to tnl->clipspace.vertex_buf */
188
189 /* Fallback rasterization functions
190 */
191 intel_point_func draw_point;
192 intel_line_func draw_line;
193 intel_tri_func draw_tri;
194
195 /* These refer to the current drawing buffer:
196 */
197 int drawX, drawY; /**< origin of drawing area within region */
198 GLuint numClipRects; /**< cliprects for drawing */
199 drm_clip_rect_t *pClipRects;
200 drm_clip_rect_t fboRect; /**< cliprect for FBO rendering */
201
202 int perf_boxes;
203
204 GLuint do_usleeps;
205 int do_irqs;
206 GLuint irqsEmitted;
207
208 drm_context_t hHWContext;
209 drmLock *driHwLock;
210 int driFd;
211
212 __DRIdrawablePrivate *driDrawable;
213 __DRIscreenPrivate *driScreen;
214 intelScreenPrivate *intelScreen;
215 drmI830Sarea *sarea;
216
217 GLuint lastStamp;
218
219 /**
220 * Configuration cache
221 */
222 driOptionCache optionCache;
223
224 /* Last seen width/height of the screen */
225 int width;
226 int height;
227 };
228
229 /* These are functions now:
230 */
231 void LOCK_HARDWARE( struct intel_context *intel );
232 void UNLOCK_HARDWARE( struct intel_context *intel );
233
234 extern char *__progname;
235
236
237 #define SUBPIXEL_X 0.125
238 #define SUBPIXEL_Y 0.125
239
240 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
241
242 #define INTEL_FIREVERTICES(intel) \
243 do { \
244 if ((intel)->prim.flush) \
245 (intel)->prim.flush(intel); \
246 } while (0)
247
248 /* ================================================================
249 * Color packing:
250 */
251
252 #define INTEL_PACKCOLOR4444(r,g,b,a) \
253 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
254
255 #define INTEL_PACKCOLOR1555(r,g,b,a) \
256 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
257 ((a) ? 0x8000 : 0))
258
259 #define INTEL_PACKCOLOR565(r,g,b) \
260 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
261
262 #define INTEL_PACKCOLOR8888(r,g,b,a) \
263 ((a<<24) | (r<<16) | (g<<8) | b)
264
265
266
267 /* ================================================================
268 * From linux kernel i386 header files, copes with odd sizes better
269 * than COPY_DWORDS would:
270 * XXX Put this in src/mesa/main/imports.h ???
271 */
272 #if defined(i386) || defined(__i386__)
273 static INLINE void *
274 __memcpy(void *to, const void *from, size_t n)
275 {
276 int d0, d1, d2;
277 __asm__ __volatile__("rep ; movsl\n\t"
278 "testb $2,%b4\n\t"
279 "je 1f\n\t"
280 "movsw\n"
281 "1:\ttestb $1,%b4\n\t"
282 "je 2f\n\t"
283 "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
284 :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
285 :"memory");
286 return (to);
287 }
288 #else
289 #define __memcpy(a,b,c) memcpy(a,b,c)
290 #endif
291
292
293
294 /* ================================================================
295 * Debugging:
296 */
297 #define DO_DEBUG 1
298 #if DO_DEBUG
299 extern int INTEL_DEBUG;
300 #else
301 #define INTEL_DEBUG 0
302 #endif
303
304 #define DEBUG_TEXTURE 0x1
305 #define DEBUG_STATE 0x2
306 #define DEBUG_IOCTL 0x4
307 #define DEBUG_BLIT 0x8
308 #define DEBUG_MIPTREE 0x10
309 #define DEBUG_FALLBACKS 0x20
310 #define DEBUG_VERBOSE 0x40
311 #define DEBUG_BATCH 0x80
312 #define DEBUG_PIXEL 0x100
313 #define DEBUG_BUFMGR 0x200
314 #define DEBUG_REGION 0x400
315 #define DEBUG_FBO 0x800
316 #define DEBUG_LOCK 0x1000
317 #define DEBUG_SYNC 0x2000
318
319 #define DBG(...) do { if (INTEL_DEBUG & FILE_DEBUG_FLAG) _mesa_printf(__VA_ARGS__); } while(0)
320
321
322 #define PCI_CHIP_845_G 0x2562
323 #define PCI_CHIP_I830_M 0x3577
324 #define PCI_CHIP_I855_GM 0x3582
325 #define PCI_CHIP_I865_G 0x2572
326 #define PCI_CHIP_I915_G 0x2582
327 #define PCI_CHIP_I915_GM 0x2592
328 #define PCI_CHIP_I945_G 0x2772
329 #define PCI_CHIP_I945_GM 0x27A2
330 #define PCI_CHIP_I945_GME 0x27AE
331 #define PCI_CHIP_G33_G 0x29C2
332 #define PCI_CHIP_Q35_G 0x29B2
333 #define PCI_CHIP_Q33_G 0x29D2
334
335
336 /* ================================================================
337 * intel_context.c:
338 */
339
340 extern GLboolean intelInitContext(struct intel_context *intel,
341 const __GLcontextModes * mesaVis,
342 __DRIcontextPrivate * driContextPriv,
343 void *sharedContextPrivate,
344 struct dd_function_table *functions);
345
346 extern void intelGetLock(struct intel_context *intel, GLuint flags);
347
348 extern void intelFinish(GLcontext * ctx);
349 extern void intelFlush(GLcontext * ctx);
350
351 extern void intelInitDriverFunctions(struct dd_function_table *functions);
352
353
354 /* ================================================================
355 * intel_state.c:
356 */
357 extern void intelInitStateFuncs(struct dd_function_table *functions);
358
359 #define COMPAREFUNC_ALWAYS 0
360 #define COMPAREFUNC_NEVER 0x1
361 #define COMPAREFUNC_LESS 0x2
362 #define COMPAREFUNC_EQUAL 0x3
363 #define COMPAREFUNC_LEQUAL 0x4
364 #define COMPAREFUNC_GREATER 0x5
365 #define COMPAREFUNC_NOTEQUAL 0x6
366 #define COMPAREFUNC_GEQUAL 0x7
367
368 #define STENCILOP_KEEP 0
369 #define STENCILOP_ZERO 0x1
370 #define STENCILOP_REPLACE 0x2
371 #define STENCILOP_INCRSAT 0x3
372 #define STENCILOP_DECRSAT 0x4
373 #define STENCILOP_INCR 0x5
374 #define STENCILOP_DECR 0x6
375 #define STENCILOP_INVERT 0x7
376
377 #define LOGICOP_CLEAR 0
378 #define LOGICOP_NOR 0x1
379 #define LOGICOP_AND_INV 0x2
380 #define LOGICOP_COPY_INV 0x3
381 #define LOGICOP_AND_RVRSE 0x4
382 #define LOGICOP_INV 0x5
383 #define LOGICOP_XOR 0x6
384 #define LOGICOP_NAND 0x7
385 #define LOGICOP_AND 0x8
386 #define LOGICOP_EQUIV 0x9
387 #define LOGICOP_NOOP 0xa
388 #define LOGICOP_OR_INV 0xb
389 #define LOGICOP_COPY 0xc
390 #define LOGICOP_OR_RVRSE 0xd
391 #define LOGICOP_OR 0xe
392 #define LOGICOP_SET 0xf
393
394 #define BLENDFACT_ZERO 0x01
395 #define BLENDFACT_ONE 0x02
396 #define BLENDFACT_SRC_COLR 0x03
397 #define BLENDFACT_INV_SRC_COLR 0x04
398 #define BLENDFACT_SRC_ALPHA 0x05
399 #define BLENDFACT_INV_SRC_ALPHA 0x06
400 #define BLENDFACT_DST_ALPHA 0x07
401 #define BLENDFACT_INV_DST_ALPHA 0x08
402 #define BLENDFACT_DST_COLR 0x09
403 #define BLENDFACT_INV_DST_COLR 0x0a
404 #define BLENDFACT_SRC_ALPHA_SATURATE 0x0b
405 #define BLENDFACT_CONST_COLOR 0x0c
406 #define BLENDFACT_INV_CONST_COLOR 0x0d
407 #define BLENDFACT_CONST_ALPHA 0x0e
408 #define BLENDFACT_INV_CONST_ALPHA 0x0f
409 #define BLENDFACT_MASK 0x0f
410
411 extern int intel_translate_compare_func(GLenum func);
412 extern int intel_translate_stencil_op(GLenum op);
413 extern int intel_translate_blend_factor(GLenum factor);
414 extern int intel_translate_logic_op(GLenum opcode);
415
416
417 /*======================================================================
418 * Inline conversion functions.
419 * These are better-typed than the macros used previously:
420 */
421 static INLINE struct intel_context *
422 intel_context(GLcontext * ctx)
423 {
424 return (struct intel_context *) ctx;
425 }
426
427 #endif