summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/i915tex/intel_context.h
blob: 6bb7e13166bab23d9017f6ea83d25213f486bf6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
/**************************************************************************
 * 
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

#ifndef INTELCONTEXT_INC
#define INTELCONTEXT_INC



#include "mtypes.h"
#include "drm.h"
#include "mm.h"
#include "texmem.h"

#include "intel_screen.h"
#include "clip/clip_context.h"

#include "i915_drm.h"
#include "i830_common.h"

#include "intel_debug.h"

#ifndef DRM_I915_HWZ

#define DRM_I915_HWZ		0x11

#define DRM_I915_HWZ_ALLOC	2
#define DRM_I915_HWZ_RENDER	3

typedef struct drm_i915_hwz {
	unsigned int op;
	union {
		struct drm_i915_hwz_alloc {
			unsigned int num_buffers;
			unsigned int num_cliprects;
			uint64_t cliprects;
		} alloc;
		struct drm_i915_hwz_render {
			unsigned int bpl_num;
			unsigned int batch_start;
			int DR1;
			int DR4;
			unsigned int static_state_offset;
			unsigned int static_state_size;
			unsigned int wait_flips;
		} render;
	} arg;
} drm_i915_hwz_t;

#endif

#define DV_PF_555  (1<<8)
#define DV_PF_565  (2<<8)
#define DV_PF_8888 (3<<8)

struct intel_region;
struct intel_context;
struct _DriBufferObject;


struct intel_texture_object;
struct intel_texture_image;
struct intel_frame_tracker;



#define INTEL_FALLBACK_DRAW_BUFFER	 0x1
#define INTEL_FALLBACK_READ_BUFFER	 0x2
#define INTEL_FALLBACK_DEPTH_BUFFER      0x4
#define INTEL_FALLBACK_STENCIL_BUFFER    0x8
#define INTEL_FALLBACK_USER		 0x10
#define INTEL_FALLBACK_RENDERMODE	 0x20
#define INTEL_FALLBACK_OTHER    	 0x40

extern void intelFallback(struct intel_context *intel, GLuint bit,
                          GLboolean mode);
#define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )

#define INTEL_WRITE_PART  0x1
#define INTEL_WRITE_FULL  0x2
#define INTEL_READ        0x4



#define INTEL_NEW_MESA                    0x1 /* Mesa state has changed */
#define INTEL_NEW_FRAGMENT_PROGRAM        0x2
#define INTEL_NEW_VERTEX_SIZE             0x4
#define INTEL_NEW_FRAG_ATTRIB_SIZES       0x8
#define INTEL_NEW_CONTEXT                 0x10 /* Lost hardware? */
#define INTEL_NEW_FALLBACK                0x20
#define INTEL_NEW_FALLBACK_PRIMS          0x40
#define INTEL_NEW_METAOPS                 0x80 /* not needed? */
#define INTEL_NEW_VBO                     0x100
#define INTEL_NEW_FENCE                   0x200	/* whatever invalidates RELOC's */
#define INTEL_NEW_CBUF                    0x400
#define INTEL_NEW_ZBUF                    0x800
#define INTEL_NEW_WINDOW_DIMENSIONS       0x1000
#define INTEL_NEW_VB_STATE                0x2000 
#define INTEL_NEW_REDUCED_PRIMITIVE       0x4000 /* still needed to turn stipple on/off */
#define INTEL_NEW_CLEAR_PARAMS            0x8000

#define INTEL_NEW_DRIVER0                 0x10000

struct intel_state_flags {
   GLuint mesa;
   GLuint intel;
   GLuint extra;
};


struct intel_context_state {
   struct gl_colorbuffer_attrib	*Color;
   struct gl_depthbuffer_attrib	*Depth;
   struct gl_fog_attrib		*Fog;
   struct gl_hint_attrib	*Hint;
   struct gl_light_attrib	*Light;
   struct gl_line_attrib	*Line;
   struct gl_point_attrib	*Point;
   struct gl_polygon_attrib	*Polygon;
   GLuint                       *PolygonStipple;
   struct gl_scissor_attrib	*Scissor;
   struct gl_stencil_attrib	*Stencil;
   struct gl_texture_attrib	*Texture;
   struct gl_transform_attrib	*Transform;
   struct gl_viewport_attrib	*Viewport;
   struct gl_vertex_program_state *VertexProgram; 
   struct gl_fragment_program_state *FragmentProgram;

   GLframebuffer *DrawBuffer;	
   GLframebuffer *ReadBuffer;	
   GLenum RenderMode;

   GLuint _ColorDrawBufferMask0; /* ???  */

   struct intel_region *draw_region; /* INTEL_NEW_CBUF */
   struct intel_region *depth_region; /* INTEL_NEW_ZBUF */

   GLuint clearparams;

   struct gl_fragment_program *fp;

   /* Indexed rendering support.  GEN3 specific.
    */
   struct _DriBufferObject *vbo;
   GLuint vbo_offset;


   /* Track dirty flags for software state:
    */
   struct intel_state_flags dirty;


   /* A hardware state tracker:
    */
   GLuint driver_state_size;
   void *current;		/* pointer to subdriver state */
   void *hardware;		/* malloc'ed */
   GLboolean force_load;
};

/* A single atom of derived state
 */
struct intel_tracked_state {
   struct intel_state_flags dirty;
   void (*update)( struct intel_context *intel );
};

struct intel_driver_state {
   struct intel_tracked_state **atoms;
   GLuint nr_atoms;
};


struct intel_hw_dirty {
   GLuint prim:2;
   GLuint force_reload:1;
   GLuint swz_reset:1;
   GLuint dirty:28;
};


struct intel_render;


struct intel_context
{
   GLcontext ctx;               /* the parent class */

   struct
   {
      void (*destroy) (struct intel_context * intel);
      void (*lost_hardware) (struct intel_context * intel);

      void (*render_start) (struct intel_context * intel);
      void (*set_draw_region) (struct intel_context * intel,
                               struct intel_region * draw_region,
                               struct intel_region * depth_region);

      GLuint (*flush_cmd) (void);

      /* Do with metaops: */
      void (*rotate_window) (struct intel_context * intel,
                             __DRIdrawablePrivate * dPriv, GLuint srcBuf);



      GLboolean (*debug_packet)(struct debug_stream *stream);

      /* Must be exact
       */
      GLuint (*get_state_emit_size) (struct intel_context *intel,
				     struct intel_hw_dirty flags );


      struct intel_hw_dirty (*diff_states) ( const void *old_state,
					     const void *new_state );

      

      void (*emit_hardware_state) (struct intel_context *intel,
				   GLuint *ptr,
				   const void *state,
				   struct intel_hw_dirty flags );

      GLboolean (*check_indirect_space) (struct intel_context *intel);

   } vtbl;

   GLint refcount;

   struct intel_context_state state;
   
   struct intel_driver_state driver_state;
   

   struct {
      /* Will be allocated on demand if needed.   
       */
      struct intel_context_state state;
      struct gl_fragment_program *fp, *fp_tex;

      struct intel_region *saved_draw_region;
      struct intel_region *saved_depth_region;

      GLuint restore_draw_mask;
      struct gl_fragment_program *restore_fp;

      struct gl_texture_object *texobj;

      GLboolean active;
   } metaops;


   struct {
      GLuint offset;
      GLuint size;
      GLuint used;
      GLubyte *map;
   } cmdstream;

   /* All the known rasterizers:
    */
   struct clip_render *classic;
   struct clip_render *swrender;
   struct clip_render *mixed;
   struct clip_render *swz;
   struct clip_render *hwz;

   /* Current active rasterizer: 
    */
   struct clip_render *render;

   /* Track frame events to help decide which renderer to use:
    */
   struct intel_frame_tracker *ft;

   /* The clip/setup engine, which sits between tnl and us, and which
    * drives all the drawing:
    */
   struct clip_context *clip;

   /* State to keep it fed: 
    */
   struct clip_state clip_state;

   /* State we get back from it:
    */
   struct clip_vb_state clip_vb_state;
   GLuint fallback_prims:16;

   GLenum hw_reduced_prim;
   GLuint Fallback;


   struct _DriFenceObject *last_swap_fence;
   struct _DriFenceObject *first_swap_fence;

   struct intel_batchbuffer *batch;
   struct intel_vb *vb;



   GLuint ClearColor565;
   GLuint ClearColor8888;


   GLfloat polygon_offset_scale;        /* dependent on depth_scale, bpp */

   GLboolean locked;
   GLboolean contended_lock;


   GLboolean hw_stencil;

   GLboolean strict_conformance;

   /* AGP memory buffer manager:
    */
   struct bufmgr *bm;

   /* Counter to track program string changes:
    */
   GLuint program_id;

   /* Track TNL attrib sizes:
    */
   GLuint frag_attrib_sizes;
   GLuint frag_attrib_varying;

   /* These refer to the current drawing buffer:
    */
   int drawX, drawY;            /**< origin of drawing area within region */
   GLuint numClipRects;         /**< cliprects for drawing */
   drm_clip_rect_t *pClipRects;
   drm_clip_rect_t fboRect;     /**< cliprect for FBO rendering */

   drm_i915_irq_wait_t iw;

   drm_context_t hHWContext;
   drmLock *driHwLock;
   int driFd;

   __DRIdrawablePrivate *driDrawable;
   __DRIscreenPrivate *driScreen;
   intelScreenPrivate *intelScreen;
   drmI830Sarea *sarea;

   GLuint lastStamp;

   /**
    * Configuration cache
    */
   driOptionCache optionCache;

  /* Rotation. Need to match that of the
   * current screen.
   */

  int width;
  int height;
  int current_rotation;
};


extern char *__progname;


#define SUBPIXEL_X 0.125
#define SUBPIXEL_Y 0.125

#define INTEL_FIREVERTICES(intel) intel->render->flush( intel->render )	

/* ================================================================
 * Color packing:
 */

#define INTEL_PACKCOLOR4444(r,g,b,a) \
  ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))

#define INTEL_PACKCOLOR1555(r,g,b,a) \
  ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
    ((a) ? 0x8000 : 0))

#define INTEL_PACKCOLOR565(r,g,b) \
  ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))

#define INTEL_PACKCOLOR8888(r,g,b,a) \
  ((a<<24) | (r<<16) | (g<<8) | b)






#define PCI_CHIP_845_G			0x2562
#define PCI_CHIP_I830_M			0x3577
#define PCI_CHIP_I855_GM		0x3582
#define PCI_CHIP_I865_G			0x2572
#define PCI_CHIP_I915_G			0x2582
#define PCI_CHIP_I915_GM		0x2592
#define PCI_CHIP_I945_G			0x2772
#define PCI_CHIP_I945_GM		0x27A2


/* ================================================================
 * intel_context.c:
 */

extern GLboolean intelInitContext(struct intel_context *intel,
                                  const __GLcontextModes * mesaVis,
                                  __DRIcontextPrivate * driContextPriv,
                                  void *sharedContextPrivate,
                                  struct dd_function_table *functions);

extern void intelGetLock(struct intel_context *intel, GLuint flags);

extern void intelFinish(GLcontext * ctx);
extern void intelFlush(GLcontext * ctx);

extern void intelInitDriverFunctions(struct dd_function_table *functions);

void intel_lost_hardware( struct intel_context *intel );


/*======================================================================
 * intel_swrast.c 
 */
struct clip_render *intel_create_swrast_render( struct intel_context *intel );


/*======================================================================
 * intel_classic.c 
 */
struct clip_render *intel_create_classic_render( struct intel_context *intel );


/*======================================================================
 * intel_hwz.c 
 */
struct clip_render *intel_create_hwz_render( struct intel_context *intel );

/*======================================================================
 * intel_clears.c 
 */
void intelClear(GLcontext *ctx, GLbitfield mask);
void intelClearColor(GLcontext * ctx, const GLfloat color[4]);



/*======================================================================
 * Inline conversion functions.  
 * These are better-typed than the macros used previously:
 */
static INLINE struct intel_context *
intel_context(GLcontext * ctx)
{
   return (struct intel_context *) ctx;
}

static INLINE struct intel_texture_object *
intel_texture_object(struct gl_texture_object *obj)
{
   return (struct intel_texture_object *) obj;
}

static INLINE struct intel_texture_image *
intel_texture_image(struct gl_texture_image *img)
{
   return (struct intel_texture_image *) img;
}

static INLINE struct intel_framebuffer *
intel_get_fb( struct intel_context *intel )
{
   return (struct intel_framebuffer *) intel->driDrawable->driverPrivate;
}

extern struct intel_renderbuffer *
intel_renderbuffer(struct gl_renderbuffer *rb);


#endif