fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.h
index 3802deead98a3c229b87706b7c7411e6661f5ae3..8503070965d584ed11e54594fc23244ca6d57531 100644 (file)
@@ -1,6 +1,5 @@
-/* $XFree86$ */
-/**************************************************************************
-
+/* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */
+/*
 Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
 
 The Weather Channel (TM) funded Tungsten Graphics to develop the
@@ -37,11 +36,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __R200_CONTEXT_H__
 #define __R200_CONTEXT_H__
 
-#ifdef GLX_DIRECT_RENDERING
-
-#include <inttypes.h>
+#include "tnl/t_vertex.h"
+#include "drm.h"
+#include "radeon_drm.h"
 #include "dri_util.h"
-#include "radeon_common.h"
 #include "texmem.h"
 
 #include "macros.h"
@@ -49,7 +47,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "colormac.h"
 #include "r200_reg.h"
 
-#define ENABLE_HW_3D_TEXTURE 0  /* XXX this is temporary! */
+#define ENABLE_HW_3D_TEXTURE 1  /* XXX this is temporary! */
 
 struct r200_context;
 typedef struct r200_context r200ContextRec;
@@ -61,14 +59,12 @@ typedef struct r200_context *r200ContextPtr;
 
 /* Flags for software fallback cases */
 /* See correponding strings in r200_swtcl.c */
-#define R200_FALLBACK_TEXTURE           0x1
-#define R200_FALLBACK_DRAW_BUFFER       0x2
-#define R200_FALLBACK_STENCIL           0x4
-#define R200_FALLBACK_RENDER_MODE       0x8
-#define R200_FALLBACK_BLEND_EQ          0x10
-#define R200_FALLBACK_BLEND_FUNC        0x20
-#define R200_FALLBACK_DISABLE           0x40
-#define R200_FALLBACK_BORDER_MODE       0x80
+#define R200_FALLBACK_TEXTURE           0x01
+#define R200_FALLBACK_DRAW_BUFFER       0x02
+#define R200_FALLBACK_STENCIL           0x04
+#define R200_FALLBACK_RENDER_MODE       0x08
+#define R200_FALLBACK_DISABLE           0x10
+#define R200_FALLBACK_BORDER_MODE       0x20
 
 /* The blit width for texture uploads
  */
@@ -96,25 +92,31 @@ typedef void (*r200_point_func)( r200ContextPtr,
 
 struct r200_colorbuffer_state {
    GLuint clear;
+#if 000
    GLint drawOffset, drawPitch;
+#endif
+   int roundEnable;
 };
 
 
 struct r200_depthbuffer_state {
+   GLuint clear;
    GLfloat scale;
 };
 
+#if 000
 struct r200_pixel_state {
    GLint readOffset, readPitch;
 };
+#endif
 
 struct r200_scissor_state {
-   XF86DRIClipRectRec rect;
+   drm_clip_rect_t rect;
    GLboolean enabled;
 
    GLuint numClipRects;                        /* Cliprects active */
    GLuint numAllocedClipRects;         /* Cliprects available */
-   XF86DRIClipRectPtr pClipRects;
+   drm_clip_rect_t *pClipRects;
 };
 
 struct r200_stencilbuffer_state {
@@ -130,7 +132,11 @@ struct r200_stipple_state {
 
 #define TEX_0   0x1
 #define TEX_1   0x2
-#define TEX_ALL 0x3
+#define TEX_2  0x4
+#define TEX_3  0x8
+#define TEX_4  0x10
+#define TEX_5  0x20
+#define TEX_ALL 0x3f
 
 typedef struct r200_tex_obj r200TexObj, *r200TexObjPtr;
 
@@ -149,7 +155,7 @@ struct r200_tex_obj {
                                           brought into the
                                           texunit. */
 
-   drmRadeonTexImage image[6][RADEON_MAX_TEXTURE_LEVELS];
+   drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS];
                                        /* Six, for the cube faces */
 
    GLuint pp_txfilter;                 /* hardware register values */
@@ -163,16 +169,18 @@ struct r200_tex_obj {
    GLuint pp_cubic_faces;              /* cube face 1,2,3,4 log2 sizes */
 
    GLboolean  border_fallback;
+
+   GLuint tile_bits;                   /* hw texture tile bits used on this texture */
 };
 
 
 struct r200_texture_env_state {
    r200TexObjPtr texobj;
-   GLenum format;
-   GLenum envMode;
+   GLuint outputreg;
+   GLuint unitneeded;
 };
 
-#define R200_MAX_TEXTURE_UNITS 3
+#define R200_MAX_TEXTURE_UNITS 6
 
 struct r200_texture_state {
    struct r200_texture_env_state unit[R200_MAX_TEXTURE_UNITS];
@@ -186,6 +194,7 @@ struct r200_state_atom {
    GLuint idx;
    int *cmd;                            /* one or more cmd's */
    int *lastcmd;                        /* one or more cmd's */
+   GLboolean dirty;
    GLboolean (*check)( GLcontext *, int );    /* is this state active? */
 };
    
@@ -211,7 +220,12 @@ struct r200_state_atom {
 #define CTX_RB3D_COLOROFFSET  11
 #define CTX_CMD_2             12 /* why */
 #define CTX_RB3D_COLORPITCH   13 /* why */
-#define CTX_STATE_SIZE        14
+#define CTX_STATE_SIZE_OLDDRM 14
+#define CTX_CMD_3             14
+#define CTX_RB3D_BLENDCOLOR   15
+#define CTX_RB3D_ABLENDCNTL   16
+#define CTX_RB3D_CBLENDCNTL   17
+#define CTX_STATE_SIZE_NEWDRM 18
 
 #define SET_CMD_0               0
 #define SET_SE_CNTL             1
@@ -264,12 +278,17 @@ struct r200_state_atom {
 #define TEX_PP_TXSIZE               4  /*2c0c*/
 #define TEX_PP_TXPITCH              5  /*2c10*/
 #define TEX_PP_BORDER_COLOR         6  /*2c14*/
-#define TEX_CMD_1                   7
-#define TEX_PP_TXOFFSET             8  /*2d00 */
-#define TEX_STATE_SIZE              9
-
-#define CUBE_CMD_0                  0  /* 1 register follows */
-#define CUBE_PP_CUBIC_FACES         1  /* 0x2c18 */
+#define TEX_CMD_1_OLDDRM            7
+#define TEX_PP_TXOFFSET_OLDDRM      8  /*2d00 */
+#define TEX_STATE_SIZE_OLDDRM       9
+#define TEX_PP_CUBIC_FACES          7
+#define TEX_PP_TXMULTI_CTL          8
+#define TEX_CMD_1_NEWDRM            9
+#define TEX_PP_TXOFFSET_NEWDRM     10
+#define TEX_STATE_SIZE_NEWDRM      11
+
+#define CUBE_CMD_0                  0  /* 1 register follows */ /* this command unnecessary */
+#define CUBE_PP_CUBIC_FACES         1  /* 0x2c18 */             /* with new enough drm */
 #define CUBE_CMD_1                  2  /* 5 registers follow */
 #define CUBE_PP_CUBIC_OFFSET_F1     3  /* 0x2d04 */
 #define CUBE_PP_CUBIC_OFFSET_F2     4  /* 0x2d08 */
@@ -294,6 +313,25 @@ struct r200_state_atom {
 #define TF_TFACTOR_5                6
 #define TF_STATE_SIZE               7
 
+#define ATF_CMD_0                   0
+#define ATF_TFACTOR_0               1
+#define ATF_TFACTOR_1               2
+#define ATF_TFACTOR_2               3
+#define ATF_TFACTOR_3               4
+#define ATF_TFACTOR_4               5
+#define ATF_TFACTOR_5               6
+#define ATF_TFACTOR_6               7
+#define ATF_TFACTOR_7               8
+#define ATF_STATE_SIZE              9
+
+/* ATI_FRAGMENT_SHADER */
+#define AFS_CMD_0                 0
+#define AFS_IC0                   1 /* 2f00 */
+#define AFS_IC1                   2 /* 2f04 */
+#define AFS_IA0                   3 /* 2f08 */
+#define AFS_IA1                   4 /* 2f0c */
+#define AFS_STATE_SIZE           33
+
 #define TCL_CMD_0                 0
 #define TCL_LIGHT_MODEL_CTL_0     1
 #define TCL_LIGHT_MODEL_CTL_1     2
@@ -359,10 +397,21 @@ struct r200_state_atom {
 #define VTX_STATE_CNTL          8
 #define VTX_STATE_SIZE          9
 
+/* SPR - point sprite state
+ */
+#define SPR_CMD_0             0
+#define SPR_POINT_SPRITE_CNTL 1
+#define SPR_STATE_SIZE        2
 
 #define VTX_COLOR(v,n)   (((v)>>(R200_VTX_COLOR_0_SHIFT+(n)*2))&\
                          R200_VTX_COLOR_MASK)
 
+/**
+ * Given the \c R200_SE_VTX_FMT_1 for the current vertex state, determine
+ * how many components are in texture coordinate \c n.
+ */
+#define VTX_TEXn_COUNT(v,n)   (((v) >> (3 * n)) & 0x07)
+
 #define MAT_CMD_0              0
 #define MAT_ELT_0              1
 #define MAT_STATE_SIZE         17
@@ -398,9 +447,9 @@ struct r200_state_atom {
 #define LIT_DIRECTION_Y            18
 #define LIT_DIRECTION_Z            19
 #define LIT_DIRECTION_W            20
-#define LIT_ATTEN_CONST            21
+#define LIT_ATTEN_QUADRATIC        21
 #define LIT_ATTEN_LINEAR           22
-#define LIT_ATTEN_QUADRATIC        23
+#define LIT_ATTEN_CONST            23
 #define LIT_ATTEN_XXX              24
 #define LIT_CMD_1                  25
 #define LIT_SPOT_DCD               26
@@ -409,7 +458,7 @@ struct r200_state_atom {
 #define LIT_SPOT_CUTOFF            29
 #define LIT_SPECULAR_THRESH        30
 #define LIT_RANGE_CUTOFF           31 /* ? */
-#define LIT_RANGE_ATTEN            32 /* ? */
+#define LIT_ATTEN_CONST_INV        32
 #define LIT_STATE_SIZE             33
 
 /* Fog
@@ -470,14 +519,15 @@ struct r200_state_atom {
 #define CST_SE_TCL_INPUT_VTX_3                17
 #define CST_STATE_SIZE                        18
 
-
+#define PRF_CMD_0         0
+#define PRF_PP_TRI_PERF   1
+#define PRF_PP_PERF_CNTL  2
+#define PRF_STATE_SIZE    3
 
 
 struct r200_hw_state {
-   /* All state should be on one of these lists:
-    */
-   struct r200_state_atom dirty; /* dirty list head placeholder */
-   struct r200_state_atom clean; /* clean list head placeholder */
+   /* Head of the linked list of state atoms. */
+   struct r200_state_atom atomlist;
 
    /* Hardware state, stored as cmdbuf commands:  
     *   -- Need to doublebuffer for
@@ -499,18 +549,25 @@ struct r200_hw_state {
    struct r200_state_atom cst;
    struct r200_state_atom tam;
    struct r200_state_atom tf;
-   struct r200_state_atom tex[2];
-   struct r200_state_atom cube[2];
+   struct r200_state_atom tex[6];
+   struct r200_state_atom cube[6];
    struct r200_state_atom zbs;
-   struct r200_state_atom mtl[2]; 
-   struct r200_state_atom mat[5]; 
+   struct r200_state_atom mtl[2];
+   struct r200_state_atom mat[9];
    struct r200_state_atom lit[8]; /* includes vec, scl commands */
    struct r200_state_atom ucp[6];
    struct r200_state_atom pix[6]; /* pixshader stages */
    struct r200_state_atom eye; /* eye pos */
    struct r200_state_atom grd; /* guard band clipping */
-   struct r200_state_atom fog; 
-   struct r200_state_atom glt; 
+   struct r200_state_atom fog;
+   struct r200_state_atom glt;
+   struct r200_state_atom prf;
+   struct r200_state_atom afs[2];
+   struct r200_state_atom atf;
+   struct r200_state_atom spr;
+
+   int max_state_size; /* Number of bytes necessary for a full state emit. */
+   GLboolean is_dirty, all_dirty;
 };
 
 struct r200_state {
@@ -518,11 +575,14 @@ struct r200_state {
     */
    struct r200_colorbuffer_state color;
    struct r200_depthbuffer_state depth;
+#if 00
    struct r200_pixel_state pixel;
+#endif
    struct r200_scissor_state scissor;
    struct r200_stencilbuffer_state stencil;
    struct r200_stipple_state stipple;
    struct r200_texture_state texture;
+   GLuint envneeded;
 };
 
 /* Need refcounting on dma buffers:
@@ -532,7 +592,7 @@ struct r200_dma_buffer {
    drmBufPtr buf;
 };
 
-#define GET_START(rvb) (rmesa->r200Screen->agp_buffer_offset +         \
+#define GET_START(rvb) (rmesa->r200Screen->gart_buffer_offset +                \
                        (rvb)->address - rmesa->dma.buf0_address +      \
                        (rvb)->start)
 
@@ -566,8 +626,8 @@ struct r200_dri_mirror {
    __DRIscreenPrivate  *screen;        /* DRI screen */
    __DRIdrawablePrivate        *drawable;      /* DRI drawable bound to this ctx */
 
-   drmContext hwContext;
-   drmLock *hwLock;
+   drm_context_t hwContext;
+   drm_hw_lock_t *hwLock;
    int fd;
    int drmMinor;
 };
@@ -591,7 +651,8 @@ struct r200_tcl_info {
    GLint last_offset;
    GLuint hw_primitive;
 
-   struct r200_dma_region *aos_components[8];
+/* FIXME: what's the maximum number of components? */
+   struct r200_dma_region *aos_components[11];
    GLuint nr_aos_components;
 
    GLuint *Elts;
@@ -609,13 +670,29 @@ struct r200_tcl_info {
 /* r200_swtcl.c
  */
 struct r200_swtcl_info {
-   GLuint SetupIndex;
-   GLuint SetupNewInputs;
    GLuint RenderIndex;
+   
+   /**
+    * Size of a hardware vertex.  This is calculated when \c ::vertex_attrs is
+    * installed in the Mesa state vector.
+    */
    GLuint vertex_size;
-   GLuint vertex_stride_shift;
-   GLuint vertex_format;
-   char *verts;
+
+   /**
+    * Attributes instructing the Mesa TCL pipeline where / how to put vertex
+    * data in the hardware buffer.
+    */
+   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+
+   /**
+    * Number of elements of \c ::vertex_attrs that are actually used.
+    */
+   GLuint vertex_attr_count;
+
+   /**
+    * Cached pointer to the buffer where Mesa will store vertex data.
+    */
+   GLubyte *verts;
 
    /* Fallback rasterization functions
     */
@@ -627,6 +704,21 @@ struct r200_swtcl_info {
    GLenum render_primitive;
    GLuint numverts;
 
+   /**
+    * Offset of the 4UB color data within a hardware (swtcl) vertex.
+    */
+   GLuint coloroffset;
+
+   /**
+    * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
+    */
+   GLuint specoffset;
+
+   /**
+    * Should Mesa project vertex data or will the hardware do it?
+    */
+   GLboolean needproj;
+
    struct r200_dma_region indexed_verts;
 };
 
@@ -670,14 +762,20 @@ struct dfn_lists {
    struct dynfn SecondaryColor3fvEXT;
    struct dynfn Normal3f;
    struct dynfn Normal3fv;
+   struct dynfn TexCoord3f;
+   struct dynfn TexCoord3fv;
    struct dynfn TexCoord2f;
    struct dynfn TexCoord2fv;
    struct dynfn TexCoord1f;
    struct dynfn TexCoord1fv;
+   struct dynfn MultiTexCoord3fARB;
+   struct dynfn MultiTexCoord3fvARB;
    struct dynfn MultiTexCoord2fARB;
    struct dynfn MultiTexCoord2fvARB;
    struct dynfn MultiTexCoord1fARB;
    struct dynfn MultiTexCoord1fvARB;
+   struct dynfn FogCoordfEXT;
+   struct dynfn FogCoordfvEXT;
 };
 
 struct dfn_generators {
@@ -699,14 +797,20 @@ struct dfn_generators {
    struct dynfn *(*SecondaryColor3fvEXT)( GLcontext *, const int * );
    struct dynfn *(*Normal3f)( GLcontext *, const int * );
    struct dynfn *(*Normal3fv)( GLcontext *, const int * );
+   struct dynfn *(*TexCoord3f)( GLcontext *, const int * );
+   struct dynfn *(*TexCoord3fv)( GLcontext *, const int * );
    struct dynfn *(*TexCoord2f)( GLcontext *, const int * );
    struct dynfn *(*TexCoord2fv)( GLcontext *, const int * );
    struct dynfn *(*TexCoord1f)( GLcontext *, const int * );
    struct dynfn *(*TexCoord1fv)( GLcontext *, const int * );
+   struct dynfn *(*MultiTexCoord3fARB)( GLcontext *, const int * );
+   struct dynfn *(*MultiTexCoord3fvARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord2fARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * );
+   struct dynfn *(*FogCoordfEXT)( GLcontext *, const int * );
+   struct dynfn *(*FogCoordfvEXT)( GLcontext *, const int * );
 };
 
 
@@ -717,30 +821,34 @@ struct r200_prim {
    GLuint prim;
 };
 
-struct r200_vbinfo {
-   GLint counter, initial_counter;
-   GLint *dmaptr;
-   void (*notify)( void );
-   GLint vertex_size;
-
-   /* A maximum total of 15 elements per vertex:  3 floats for position, 3
+   /* A maximum total of 29 elements per vertex:  3 floats for position, 3
     * floats for normal, 4 floats for color, 4 bytes for secondary color,
-    * 2 floats for each texture unit (4 floats total).
+    * 3 floats for each texture unit (18 floats total).
     * 
-    * As soon as the 3rd TMU is supported or cube maps (or 3D textures) are
-    * supported, this value will grow.
+    * we maybe need add. 4 to prevent segfault if someone specifies
+    * GL_TEXTURE6/GL_TEXTURE7 (esp. for the codegen-path) (FIXME: )
     * 
     * The position data is never actually stored here, so 3 elements could be
     * trimmed out of the buffer.
     */
-   union { float f; int i; r200_color_t color; } vertex[15];
+
+#define R200_MAX_VERTEX_SIZE ((3*6)+11)
+
+struct r200_vbinfo {
+   GLint counter, initial_counter;
+   GLint *dmaptr;
+   void (*notify)( void );
+   GLint vertex_size;
+
+   union { float f; int i; r200_color_t color; } vertex[R200_MAX_VERTEX_SIZE];
 
    GLfloat *normalptr;
    GLfloat *floatcolorptr;
+   GLfloat *fogptr;
    r200_color_t *colorptr;
    GLfloat *floatspecptr;
    r200_color_t *specptr;
-   GLfloat *texcoordptr[2];
+   GLfloat *texcoordptr[8];    /* 6 (TMU) + 2 for r200_vtxfmt_c.c when GL_TEXTURE6/7 */
 
 
    GLenum *prim;               /* &ctx->Driver.CurrentExecPrimitive */
@@ -764,8 +872,6 @@ struct r200_vbinfo {
 };
 
 
-
-
 struct r200_context {
    GLcontext *glCtx;                   /* Mesa context */
 
@@ -779,25 +885,25 @@ struct r200_context {
    unsigned              nr_heaps;
    driTexHeap          * texture_heaps[ R200_NR_TEX_HEAPS ];
    driTextureObject      swapped;
-
+   int                   texture_depth;
+   float                 initialMaxAnisotropy;
 
    /* Rasterization and vertex state:
     */
    GLuint TclFallback;
    GLuint Fallback;
    GLuint NewGLState;
-
-   
-   /* Temporaries for translating away float colors:
-    */
-   struct gl_client_array UbyteColor;
-   struct gl_client_array UbyteSecondaryColor;
+   GLuint tnl_index;   /* index of bits for last tnl_install_attrs */
 
    /* Vertex buffers
     */
    struct r200_ioctl ioctl;
    struct r200_dma dma;
    struct r200_store store;
+   /* A full state emit as of the first state emit in the main store, in case
+    * the context is lost.
+    */
+   struct r200_store backup_store;
 
    /* Page flipping
     */
@@ -808,20 +914,21 @@ struct r200_context {
    GLuint do_usleeps;
    GLuint do_irqs;
    GLuint irqsEmitted;
-   drmRadeonIrqWait iw;
+   drm_radeon_irq_wait_t iw;
 
    /* Clientdata textures;
     */
-   GLuint prefer_agp_client_texturing;
+   GLuint prefer_gart_client_texturing;
 
    /* Drawable, cliprect and scissor information
     */
    GLuint numClipRects;                        /* Cliprects for the draw buffer */
-   XF86DRIClipRectPtr pClipRects;
+   drm_clip_rect_t *pClipRects;
    unsigned int lastStamp;
    GLboolean lost_context;
+   GLboolean save_on_next_emit;
    r200ScreenPtr r200Screen;   /* Screen private DRI data */
-   RADEONSAREAPrivPtr sarea;           /* Private SAREA data */
+   drm_radeon_sarea_t *sarea;          /* Private SAREA data */
 
    /* TCL stuff
     */
@@ -831,7 +938,6 @@ struct r200_context {
    GLuint TexMatEnabled;
    GLuint TexMatCompSel;
    GLuint TexGenEnabled;
-   GLuint TexGenInputs;
    GLuint TexGenCompSel;
    GLmatrix tmpmat;
 
@@ -840,13 +946,12 @@ struct r200_context {
    GLuint vbl_seq;
    GLuint vblank_flags;
 
-   uint64_t swap_ust;
-   uint64_t swap_missed_ust;
+   int64_t swap_ust;
+   int64_t swap_missed_ust;
 
    GLuint swap_count;
    GLuint swap_missed_count;
 
-   PFNGLXGETUSTPROC get_ust;
 
    /* r200_tcl.c
     */
@@ -863,6 +968,15 @@ struct r200_context {
    /* Mirrors of some DRI state
     */
    struct r200_dri_mirror dri;
+
+   /* Configuration cache
+    */
+   driOptionCache optionCache;
+
+   GLboolean using_hyperz;
+   GLboolean texmicrotile;
+
+  struct ati_fragment_shader *afs_loaded;
 };
 
 #define R200_CONTEXT(ctx)              ((r200ContextPtr)(ctx->DriverCtx))
@@ -882,8 +996,6 @@ static __inline GLuint r200PackColor( GLuint cpp,
    }
 }
 
-#define R200_OLD_PACKETS 0
-
 
 extern void r200DestroyContext( __DRIcontextPrivate *driContextPriv );
 extern GLboolean r200CreateContext( const __GLcontextModes *glVisual,
@@ -922,5 +1034,4 @@ extern int R200_DEBUG;
 #define DEBUG_PIXEL     0x2000
 #define DEBUG_MEMORY    0x4000
 
-#endif
 #endif /* __R200_CONTEXT_H__ */