radeon_context.h 20.7 KB
Newer Older
1
2
3
4
5
6
7
8
/**
 * \file radeon_context.h
 * \brief Radeon OpenGL context definition.
 * 
 * \author Kevin E. Martin <martin@valinux.com>
 * \author Gareth Hughes <gareth@valinux.com>
 * \author Keith Whitwell <keith@tungstengraphics.com>
 */
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
 * Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
 *                      VA Linux Systems Inc., Fremont, California.
 * 
 * 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
 * on 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
 * ATI, VA LINUX SYSTEMS AND/OR THEIR 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.
 * 
35
36
 */

37
38
/* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_context.h,v 1.4 2002/09/10 00:39:39 dawes Exp $ */

39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __RADEON_CONTEXT_H__
#define __RADEON_CONTEXT_H__

struct radeon_context;
typedef struct radeon_context radeonContextRec;
typedef struct radeon_context *radeonContextPtr;

#include "mtypes.h"
#include "macros.h"
#include "radeon_lock.h"
#include "radeon_screen.h"
#include "mm.h"

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
/**
 * \brief Reference counting on DMA buffers.
 */
struct radeon_dma_buffer {
   int refcount;	/**< \brief number of retained regions in radeon_dma_buffer::buf */
   drmBufPtr buf;	/**< \brief DMA buffer */
};

/**
 * \brief Get the start of a DMA region.
 *
 * \param rvb pointer to a radeon_dma_region structure.
 *
 * \return pointer to the region start.
 */
#define GET_START(rvb) (rmesa->radeonScreen->agp_buffer_offset +	\
			(rvb)->address - rmesa->dma.buf0_address +	\
			(rvb)->start)

/**
 * \brief A retained DMA region.
 *
 * e.g. vertices for indexed vertices.
 */
struct radeon_dma_region {
   struct radeon_dma_buffer *buf;	/**< \brief DMA buffer */
   char *address;			/**< \brief buf->address */
   int start;				/**< \brief start offset from start of radeon_dma_region::buf */
   int end;				/**< \brief end offset from start of radeon_dma_region::buf */
   int ptr;				/**< \brief offsets from start of radeon_dma_region::buf */
   int aos_start;			/**< \brief array of structures start */
   int aos_stride;			/**< \brief array of structures stride */
   int aos_size;			/**< \brief array of structures size */
};

87
88
89
#if _HAVE_SWTNL
#include "radeon_swtcl.h"
#endif
90
91
92
#if _HAVE_FULL_GL
#include "radeon_vtxfmt.h"
#endif
93

94
95
96
/**
 * \brief Color buffer state.
 */
97
struct radeon_colorbuffer_state {
98
99
   GLuint clear;	/**< \brief Clear value */	
   GLint drawOffset;	/**< \brief Drawing offset */
100
   GLint drawPitch;	/**< \brief Drawing pitch */
101
102
};

103
104
105
/**
 * \brief Depth buffer state.
 */
106
struct radeon_depthbuffer_state {
107
108
   GLuint clear;	/**< \brief Clear value */
   GLfloat scale;	/**< \brief Depth scale */
109
110
};

111
112
113
/**
 * \brief Pixel state.
 */
114
struct radeon_pixel_state {
115
   GLint readOffset;	/**< \brief Reading offset */
116
   GLint readPitch;	/**< \brief Reading pitch */
117
118
};

119
120
121
/**
 * \brief Scissor state.
 */
122
123
struct radeon_scissor_state {
   XF86DRIClipRectRec rect;
124
   GLboolean enabled;			/**< \brief Whether scissoring enable */
125

126
127
128
   GLuint numClipRects;			/**< \brief Number of active cliprects */
   GLuint numAllocedClipRects;		/**< \brief Number of available cliprects */
   XF86DRIClipRectPtr pClipRects;	/**< \brief Cliprects */
129
130
};

131
132
133
/**
 * \brief Stencil buffer state.
 */
134
struct radeon_stencilbuffer_state {
135
   GLboolean hwBuffer;			/**< \brief Hardware buffer available? */
136
   GLuint clear;			/**< \brief rb3d_stencilrefmask value */
137
138
};

139
140
141
/**
 * \brief Stipple state.
 */
142
struct radeon_stipple_state {
143
   GLuint mask[32];	/**< \brief Mask */
144
145
146
147
148
149
150
151
};



#define TEX_0   0x1
#define TEX_1   0x2
#define TEX_ALL 0x3

152
153
154
155

typedef struct radeon_tex_obj radeonTexObj;	/**< \brief Alias for radeon_tex_obj. */
typedef struct radeon_tex_obj *radeonTexObjPtr;	/**< \brief Alias for radeon_tex_obj. */

156

157
158
/**
 * \brief Texture object in locally shared texture space.
159
160
161
162
 */
struct radeon_tex_obj {
   radeonTexObjPtr next, prev;

163
164
   /** \brief Mesa texture object */
   struct gl_texture_object *tObj;	
165

166
167
168
169
170
171
172
   /** \brief Memory block containing texture */
   PMemBlock memBlock;			
   
   /** \brief Offset to start of locally shared texture block */
   GLuint bufAddr;
   
   /**
173
    * \brief Flags for whether or not images need to be uploaded to local or AGP
174
175
176
    * texture space
    */
   GLuint dirty_images;			
177

178
   /**
179
180
181
    * \brief Flags (one per texture unit) for whether or not this texture
    * object has dirty hardware state (\c pp_*) that needs to be brought into
    * the texunit.
182
183
    */
   GLuint dirty_state;
184

185
186
   /** \brief Texture heap currently stored in */
   GLint heap;				
187

188
   /** \brief Texture images */
189
190
   drmRadeonTexImage image[RADEON_MAX_TEXTURE_LEVELS];

191
   /** \brief Total size of the texture including all mipmap levels */
192
   GLint totalSize;
193

Jose Fonseca's avatar
Jose Fonseca committed
194
195
196
197
198
   /**
    * \name Hardware register values.
    */
   /*@{*/
   GLuint pp_txfilter;
199
200
201
   GLuint pp_txformat;
   GLuint pp_txoffset;
   GLuint pp_border_color;
Jose Fonseca's avatar
Jose Fonseca committed
202
   /*@}*/
203

Jose Fonseca's avatar
Jose Fonseca committed
204
205
   /**
    * \name Images to upload
206
207
    * 
    * texObj->Image[firstLevel] through texObj->Image[lastLevel] are the
208
209
    * images to upload.
    */
210
   /*@{*/
211
   GLint firstLevel;     
212
213
   GLint lastLevel;
   /*@}*/
214
215
};

216
217
218
/**
 * \brief Texture environment state.
 */
219
struct radeon_texture_env_state {
220
221
222
   radeonTexObjPtr texobj; /**< \brief texture object */
   GLenum format;          /**< \brief format */
   GLenum envMode;         /**< \brief environment mode */
223
224
};

225
226
227
/**
 * \brief Texture state
 */
228
struct radeon_texture_state {
229
   struct radeon_texture_env_state unit[RADEON_MAX_TEXTURE_UNITS]; /**< \brief for each unit */
230
231
232
};


233
234
235
/**
 * \brief Radeon state atom double-linked list.
 */
236
237
struct radeon_state_atom {
   struct radeon_state_atom *next, *prev;
238
   const char *name;		         /**< \brief for debugging purposes */
239
   int cmd_size;		         /**< \brief size in bytes */
240
   GLuint is_tcl;                        /**< \brief whether is associated with TCL */
241
242
   int *cmd;			         /**< \brief one or more cmd's */
   int *lastcmd;			 /**< \brief one or more cmd's */
243
   GLboolean (*check)( GLcontext * );    /**< \brief callback to determin whether this state is active */
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
};
   


/* Trying to keep these relatively short as the variables are becoming
 * extravagently long.  Drop the RADEON_ off the front of everything -
 * I think we know we're in the radeon driver by now, and keep the
 * prefix to 3 letters unless absolutely impossible.  
 */

#define CTX_CMD_0             0
#define CTX_PP_MISC           1
#define CTX_PP_FOG_COLOR      2
#define CTX_RE_SOLID_COLOR    3
#define CTX_RB3D_BLENDCNTL    4
#define CTX_RB3D_DEPTHOFFSET  5
#define CTX_RB3D_DEPTHPITCH   6
#define CTX_RB3D_ZSTENCILCNTL 7
#define CTX_CMD_1             8
#define CTX_PP_CNTL           9
#define CTX_RB3D_CNTL         10
#define CTX_RB3D_COLOROFFSET  11
#define CTX_CMD_2             12
#define CTX_RB3D_COLORPITCH   13
#define CTX_STATE_SIZE        14

#define SET_CMD_0               0
#define SET_SE_CNTL             1
#define SET_SE_COORDFMT         2
#define SET_CMD_1               3
#define SET_SE_CNTL_STATUS      4
#define SET_STATE_SIZE          5

#define LIN_CMD_0               0
#define LIN_RE_LINE_PATTERN     1
#define LIN_RE_LINE_STATE       2
#define LIN_CMD_1               3
#define LIN_SE_LINE_WIDTH       4
#define LIN_STATE_SIZE          5

#define MSK_CMD_0               0
#define MSK_RB3D_STENCILREFMASK 1
#define MSK_RB3D_ROPCNTL        2
#define MSK_RB3D_PLANEMASK      3
#define MSK_STATE_SIZE          4

Jose Fonseca's avatar
Jose Fonseca committed
290
#define VPT_CMD_0                    0
291
292
293
294
295
296
#define VPT_SE_VPORT_XSCALE          1
#define VPT_SE_VPORT_XOFFSET         2
#define VPT_SE_VPORT_YSCALE          3
#define VPT_SE_VPORT_YOFFSET         4
#define VPT_SE_VPORT_ZSCALE          5
#define VPT_SE_VPORT_ZOFFSET         6
Jose Fonseca's avatar
Jose Fonseca committed
297
#define VPT_STATE_SIZE               7
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

#define MSC_CMD_0               0
#define MSC_RE_MISC             1
#define MSC_STATE_SIZE          2

#define TEX_CMD_0                   0
#define TEX_PP_TXFILTER             1
#define TEX_PP_TXFORMAT             2
#define TEX_PP_TXOFFSET             3
#define TEX_PP_TXCBLEND             4
#define TEX_PP_TXABLEND             5
#define TEX_PP_TFACTOR              6
#define TEX_CMD_1                   7
#define TEX_PP_BORDER_COLOR         8
#define TEX_STATE_SIZE              9

Jose Fonseca's avatar
Jose Fonseca committed
314
315
316
317
#define ZBS_CMD_0                   0
#define ZBS_SE_ZBIAS_FACTOR         1
#define ZBS_SE_ZBIAS_CONSTANT       2
#define ZBS_STATE_SIZE              3
318

Jose Fonseca's avatar
Jose Fonseca committed
319
#define TCL_CMD_0                 0
320
321
322
323
324
325
326
327
328
329
330
#define TCL_OUTPUT_VTXFMT         1
#define TCL_OUTPUT_VTXSEL         2
#define TCL_MATRIX_SELECT_0       3
#define TCL_MATRIX_SELECT_1       4
#define TCL_UCP_VERT_BLEND_CTL    5
#define TCL_TEXTURE_PROC_CTL      6
#define TCL_LIGHT_MODEL_CTL       7
#define TCL_PER_LIGHT_CTL_0       8
#define TCL_PER_LIGHT_CTL_1       9
#define TCL_PER_LIGHT_CTL_2       10
#define TCL_PER_LIGHT_CTL_3       11
Jose Fonseca's avatar
Jose Fonseca committed
331
#define TCL_STATE_SIZE            12
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

#define MTL_CMD_0            0	
#define MTL_EMMISSIVE_RED    1	
#define MTL_EMMISSIVE_GREEN  2	
#define MTL_EMMISSIVE_BLUE   3	
#define MTL_EMMISSIVE_ALPHA  4	
#define MTL_AMBIENT_RED      5
#define MTL_AMBIENT_GREEN    6
#define MTL_AMBIENT_BLUE     7
#define MTL_AMBIENT_ALPHA    8
#define MTL_DIFFUSE_RED      9
#define MTL_DIFFUSE_GREEN    10
#define MTL_DIFFUSE_BLUE     11
#define MTL_DIFFUSE_ALPHA    12
#define MTL_SPECULAR_RED     13
#define MTL_SPECULAR_GREEN   14
#define MTL_SPECULAR_BLUE    15
#define MTL_SPECULAR_ALPHA   16
#define MTL_SHININESS        17
#define MTL_STATE_SIZE       18

#define VTX_CMD_0              0
#define VTX_SE_COORD_FMT       1
#define VTX_STATE_SIZE         2

#define MAT_CMD_0              0
#define MAT_ELT_0              1
#define MAT_STATE_SIZE         17

#define GRD_CMD_0                  0
#define GRD_VERT_GUARD_CLIP_ADJ    1
#define GRD_VERT_GUARD_DISCARD_ADJ 2
#define GRD_HORZ_GUARD_CLIP_ADJ    3
#define GRD_HORZ_GUARD_DISCARD_ADJ 4
#define GRD_STATE_SIZE             5

/* position changes frequently when lighting in modelpos - separate
 * out to new state item?  
 */
#define LIT_CMD_0                  0
#define LIT_AMBIENT_RED            1
#define LIT_AMBIENT_GREEN          2
#define LIT_AMBIENT_BLUE           3
#define LIT_AMBIENT_ALPHA          4
#define LIT_DIFFUSE_RED            5
#define LIT_DIFFUSE_GREEN          6
#define LIT_DIFFUSE_BLUE           7
#define LIT_DIFFUSE_ALPHA          8
#define LIT_SPECULAR_RED           9
#define LIT_SPECULAR_GREEN         10
#define LIT_SPECULAR_BLUE          11
#define LIT_SPECULAR_ALPHA         12
#define LIT_POSITION_X             13
#define LIT_POSITION_Y             14
#define LIT_POSITION_Z             15
#define LIT_POSITION_W             16
#define LIT_DIRECTION_X            17
#define LIT_DIRECTION_Y            18
#define LIT_DIRECTION_Z            19
#define LIT_DIRECTION_W            20
#define LIT_ATTEN_CONST            21
#define LIT_ATTEN_LINEAR           22
#define LIT_ATTEN_QUADRATIC        23
#define LIT_ATTEN_XXX              24
#define LIT_CMD_1                  25
#define LIT_SPOT_DCD               26
#define LIT_SPOT_EXPONENT          27
#define LIT_SPOT_CUTOFF            28
#define LIT_SPECULAR_THRESH        29
#define LIT_RANGE_CUTOFF           30 /* ? */
#define LIT_RANGE_ATTEN            31 /* ? */
#define LIT_STATE_SIZE             32

/* Fog
 */
#define FOG_CMD_0      0
#define FOG_R          1
#define FOG_C          2
#define FOG_D          3
#define FOG_PAD        4
#define FOG_STATE_SIZE 5

/* UCP
 */
#define UCP_CMD_0      0
#define UCP_X          1
#define UCP_Y          2
#define UCP_Z          3
#define UCP_W          4
#define UCP_STATE_SIZE 5

/* GLT - Global ambient
 */
#define GLT_CMD_0      0
#define GLT_RED        1
#define GLT_GREEN      2
#define GLT_BLUE       3
#define GLT_ALPHA      4
#define GLT_STATE_SIZE 5

/* EYE
 */
#define EYE_CMD_0          0
#define EYE_X              1
#define EYE_Y              2
#define EYE_Z              3
#define EYE_RESCALE_FACTOR 4
#define EYE_STATE_SIZE     5

#define SHN_CMD_0          0
#define SHN_SHININESS      1
#define SHN_STATE_SIZE     2


446
447
448
/**
 * \brief Hardware state management.
 */
449
struct radeon_hw_state {
450
451
452
453
   /**
    * \name State
    * 
    * All state should be on one of these lists
454
    */
455
456
457
458
459
460
461
462
463
464
465
466
   /*@{*/
   struct radeon_state_atom dirty; /**< \brief dirty list head placeholder */
   struct radeon_state_atom clean; /**< \brief clean list head placeholder */
   /*@}*/

   /**
    * \name Hardware state
    * 
    * Stored as cmdbuf commands:  
    * - Need to doublebuffer for
    *   - reviving state after loss of context
    *   - eliding no-op statechange loops? (except line stipple count)
467
    */
468
   /*@{*/
469
470
471
472
473
   struct radeon_state_atom ctx;
   struct radeon_state_atom set;
   struct radeon_state_atom lin;
   struct radeon_state_atom msk;
   struct radeon_state_atom vpt;
474
   struct radeon_state_atom tcl;	/**< \ brief TCL */
475
476
477
478
   struct radeon_state_atom msc;
   struct radeon_state_atom tex[2];
   struct radeon_state_atom zbs;
   struct radeon_state_atom mtl; 
479
   struct radeon_state_atom mat[5];	/**< \brief matrix transformations */
Keith Whitwell's avatar
Keith Whitwell committed
480
#if _HAVE_LIGHTING
481
   struct radeon_state_atom lit[8];	/**< \brief includes vec, scl commands */
Keith Whitwell's avatar
Keith Whitwell committed
482
483
#endif
#if _HAVE_USERCLIP
484
   struct radeon_state_atom ucp[6];
Keith Whitwell's avatar
Keith Whitwell committed
485
#endif
486
487
488
   struct radeon_state_atom eye;	/**< \brief eye pos */
   struct radeon_state_atom grd;	/**< \brief guard band clipping */
   struct radeon_state_atom fog;	/**< \brief fog */
489
   struct radeon_state_atom glt; 
490
   /*@}*/
491
492
};

493
494
495
/**
 * \brief Derived state for internal purposes:
 */
496
struct radeon_state {
497
498
499
500
501
502
503
   struct radeon_colorbuffer_state color;	/**< \brief Color buffer */
   struct radeon_depthbuffer_state depth;	/**< \brief Depth buffer */
   struct radeon_pixel_state pixel;		/**< \brief Pixel */
   struct radeon_scissor_state scissor;		/**< \brief Scissor */
   struct radeon_stencilbuffer_state stencil;	/**< \brief Stencil buffer */
   struct radeon_stipple_state stipple;		/**< \brief Stipple */
   struct radeon_texture_state texture;		/**< \brief Textures */
504
505
};

Jose Fonseca's avatar
Jose Fonseca committed
506
507
508
/**
 * \brief Texture information
 */
509
struct radeon_texture {
Jose Fonseca's avatar
Jose Fonseca committed
510
   radeonTexObj objects[RADEON_NR_TEX_HEAPS];	/**< \brief texture objects */
511
   radeonTexObj swapped;			/**< \brief swapped texture  */
512

Jose Fonseca's avatar
Jose Fonseca committed
513
514
   memHeap_t *heap[RADEON_NR_TEX_HEAPS];	/**< \brief texture heaps */
   GLint age[RADEON_NR_TEX_HEAPS];		/**< \brief aging */
515

Jose Fonseca's avatar
Jose Fonseca committed
516
   GLint numHeaps;				/**< \brief number of active heaps */
517
518
519
520
};



Jose Fonseca's avatar
Jose Fonseca committed
521
522
523
/**
 * \brief DMA information
 */
524
struct radeon_dma {
525
   /**
526
    * \brief Active DMA region.  
527
528
529
    *
    * Allocations for vertices and retained regions come from here.  Also used
    * for emitting random vertices, these may be flushed by calling
530
    * radeon_dma::flush.
531
532
533
    */
   struct radeon_dma_region current;
   
Jose Fonseca's avatar
Jose Fonseca committed
534
535
536
   /**
    * \brief Callback to flush the vertices in radeon_dma::current.
    */
537
538
   void (*flush)( radeonContextPtr );

539
   char *buf0_address;		/**< \brief start of buf[0], for index calculations */
540
   GLuint nr_released_bufs;	/**< \brief flush after so many buffers released */
541
542
};

Jose Fonseca's avatar
Jose Fonseca committed
543
544
545
/**
 * \brief Mirror some DRI context.
 */
546
struct radeon_dri_mirror {
547
548
   __DRIcontextPrivate	*context;	/**< \brief DRI context */
   __DRIscreenPrivate	*screen;	/**< \brief DRI screen */
Jose Fonseca's avatar
Jose Fonseca committed
549
   __DRIdrawablePrivate	*drawable;	/**< \brief DRI drawable bound to this context */
550

Jose Fonseca's avatar
Jose Fonseca committed
551
552
553
554
   drmContext hwContext;		
   drmLock *hwLock;			/**< \brief hardware lock */
   int fd;				/**< \brief DRM device file descriptor */
   int drmMinor;			/**< \brief DRM device minor number */
555
556
};

Jose Fonseca's avatar
Jose Fonseca committed
557
558
559
/**
 * \brief Command buffer size
 */
560
561
#define RADEON_CMD_BUF_SZ  (8*1024) 

Jose Fonseca's avatar
Jose Fonseca committed
562
563
564
/**
 * \brief Command buffering.
 */
565
struct radeon_store {
Jose Fonseca's avatar
Jose Fonseca committed
566
567
568
569
   GLuint statenr;                  /**< \brief state number */
   GLuint primnr;                   /**< \brief primitive number */
   char cmd_buf[RADEON_CMD_BUF_SZ]; /**< \brief command buffer */
   int cmd_used;                    /**< \brief used commands */
570
571
572
573
   int elts_start;
};


574
575
/**
 * \brief TCL information.
576
577
578
579
580
 */
struct radeon_tcl_info {
   GLuint vertex_format;
   GLint last_offset;
   GLuint hw_primitive;
581
   GLuint tcl_flag;			/**< \brief Whether TCL is inabled */
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598

   struct radeon_dma_region *aos_components[8];
   GLuint nr_aos_components;

   GLuint *Elts;

   struct radeon_dma_region indexed_verts;
   struct radeon_dma_region obj;
   struct radeon_dma_region rgba;
   struct radeon_dma_region spec;
   struct radeon_dma_region fog;
   struct radeon_dma_region tex[RADEON_MAX_TEXTURE_UNITS];
   struct radeon_dma_region norm;
};



599
600
601
/**
 * \brief Retained buffer.
 */
602
struct radeon_ioctl {
603
604
   GLuint vertex_offset; /**< \brief offset of the vertex buffer */
   GLuint vertex_size;   /**< \brief size of the vertex buffer */
605
606
607
608
};



609
610
611
/**
 * \brief Radeon GL context.
 */
612
struct radeon_context {
613
614
615
616
   /**
    * \brief Mesa context.
    */
   GLcontext *glCtx;			
617

618
619
   /**
    * \name Driver and hardware state management
620
    */
621
   /*@{*/
622
623
   struct radeon_hw_state hw; /**< \brief Hardware state */
   struct radeon_state state; /**< \brief Internal state */
624
   /*@}*/
625

626
627
   /**
    * \brief Texture object bookkeeping
628
629
630
631
    */
   struct radeon_texture texture;


632
633
   /**
    * \name Rasterization and vertex state
634
    */
635
   /*@{*/
636
637
638
   GLuint TclFallback;
   GLuint Fallback;
   GLuint NewGLState;
639
   /*@}*/
640
   
641
642
   /**
    * \name Temporaries for translating away float colors
643
    */
644
   /*@{*/
645
646
   struct gl_client_array UbyteColor;
   struct gl_client_array UbyteSecondaryColor;
647
   /*@}*/
648

649
650
   /**
    * \name Vertex buffers
651
    */
652
   /*@{*/
653
   struct radeon_ioctl ioctl; /**< \brief Retained vertex buffer */
654
655
   struct radeon_dma dma;     /**< \brief DMA information */
   struct radeon_store store; /**< \brief Command buffer */
656
   /*@}*/
657

658
659
   /**
    * \brief Page flipping
660
661
662
    */
   GLuint doPageFlip;

663
664
   /**
    * \name Busy waiting
665
    */
666
   /*@{*/
667
   GLuint do_usleeps;
Jose Fonseca's avatar
Jose Fonseca committed
668
   GLuint do_irqs;		/**< \brief Do IRQs */
669
670
   GLuint irqsEmitted;		/**< \brief IRQ transition counter.
				  * \sa radeonWaitForFrameCompletion(). */
671
   drmRadeonIrqWait iw;
672
   /*@}*/
673

674
675
   /**
    * \name Drawable, cliprect and scissor information
676
    */
677
   /*@{*/
Jose Fonseca's avatar
Jose Fonseca committed
678
679
   GLuint numClipRects;			/**< \brief Number of cliprects */
   XF86DRIClipRectPtr pClipRects;	/**< \brief cliprects for the draw buffer */
680
   unsigned int lastStamp;
681
   GLboolean lost_context;		/**< \brief re-emit all state */
Jose Fonseca's avatar
Jose Fonseca committed
682
   radeonScreenPtr radeonScreen;	/**< \brief Screen private DRI data */
683
684
   RADEONSAREAPrivPtr sarea;		/**< \brief Private SAREA data */
   /*@}*/
685

686
687
   /**
    * \name TCL stuff
688
    */
689
   /*@{*/
690
691
692
693
694
695
696
   GLmatrix TexGenMatrix[RADEON_MAX_TEXTURE_UNITS];
   GLboolean recheck_texgen[RADEON_MAX_TEXTURE_UNITS];
   GLboolean TexGenNeedNormals[RADEON_MAX_TEXTURE_UNITS];
   GLuint TexMatEnabled;
   GLuint TexGenEnabled;
   GLmatrix tmpmat;
   GLuint last_ReallyEnabled;
697
   /*@}*/
698

699
700
   /**
    * \brief VBI
701
702
703
704
705
706
707
708
709
    */
   GLuint vbl_seq;

   /* radeon_tcl.c
    */
   struct radeon_tcl_info tcl;

   /* radeon_swtcl.c
    */
710
#if _HAVE_SWTNL
711
   struct radeon_swtcl_info swtcl;
712
#endif
713
714
715

   /* radeon_vtxfmt.c
    */
716
717
718
#if _HAVE_FULL_GL
   struct radeon_vbinfo vb;
#endif
719
720
   /**
    * \brief Mirrors of some DRI state
721
722
723
724
    */
   struct radeon_dri_mirror dri;
};

725
726

/**
Jose Fonseca's avatar
Jose Fonseca committed
727
 * \brief Get the pointer to the Radeon context from the GL context.
728
 */
729
730
731
#define RADEON_CONTEXT(ctx)		((radeonContextPtr)(ctx->DriverCtx))


Jose Fonseca's avatar
Jose Fonseca committed
732
733
734
/** 
 * \brief Pack color.
 *
735
 * \param cpp desired characters (bytes) per pixel. Shouble be either 2 or 4.
Jose Fonseca's avatar
Jose Fonseca committed
736
737
738
739
740
741
742
 * \param r red color component.
 * \param r green color component.
 * \param b blue color component.
 * \param a alpha color component.
 *
 * \return the packed color, or zero if \p cpp is not supported.
 */
743
744
745
746
747
748
749
750
751
752
753
754
755
756
static __inline GLuint radeonPackColor( GLuint cpp,
					GLubyte r, GLubyte g,
					GLubyte b, GLubyte a )
{
   switch ( cpp ) {
   case 2:
      return PACK_COLOR_565( r, g, b );
   case 4:
      return PACK_COLOR_8888( a, r, g, b );
   default:
      return 0;
   }
}

757

Jose Fonseca's avatar
Jose Fonseca committed
758
/******************************************************************
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
 * Debugging:
 */
#define DO_DEBUG		1

#if DO_DEBUG
extern int RADEON_DEBUG;
#else
#define RADEON_DEBUG		0
#endif

#define DEBUG_TEXTURE	0x001
#define DEBUG_STATE	0x002
#define DEBUG_IOCTL	0x004
#define DEBUG_PRIMS	0x008
#define DEBUG_VERTS	0x010
#define DEBUG_FALLBACKS	0x020
#define DEBUG_VFMT	0x040
#define DEBUG_CODEGEN	0x080
#define DEBUG_VERBOSE	0x100
#define DEBUG_DRI       0x200
#define DEBUG_DMA       0x400
#define DEBUG_SANITY    0x800

#endif /* __RADEON_CONTEXT_H__ */