merge unichrome changes from branch
[mesa.git] / src / mesa / drivers / dri / unichrome / via_context.h
index 25d9325288f1f5f94439886395991df98e079798..9db382d49cd37dfd17945e1fe288eb19c5c10650 100644 (file)
 #ifndef _VIACONTEXT_H
 #define _VIACONTEXT_H
 
-typedef struct via_context_t viaContext;
-typedef struct via_context_t *viaContextPtr;
-typedef struct via_texture_object_t *viaTextureObjectPtr;
-
 #include "dri_util.h"
 
-#ifndef _SOLO
-#include <X11/Xlibint.h>
-#endif
-
 #include "mtypes.h"
 #include "drm.h"
 #include "mm.h"
+#include "tnl/t_vertex.h"
 
 #include "via_screen.h"
 #include "via_tex.h"
 #include "via_common.h"
-#include "xf86drmVIA.h"
-#ifdef USE_XINERAMA
-#include "../../../../../include/extensions/Xinerama.h"
-#endif
+
+struct via_context;
+
+/* Chip tags.  These are used to group the adapters into
+ * related families.
+ */
+enum VIACHIPTAGS {
+    VIA_UNKNOWN = 0,
+    VIA_CLE266,
+    VIA_KM400,
+    VIA_K8M800,
+    VIA_PM800,
+    VIA_LAST
+};
+
 #define VIA_FALLBACK_TEXTURE                   0x1
 #define VIA_FALLBACK_DRAW_BUFFER               0x2
 #define VIA_FALLBACK_READ_BUFFER               0x4
@@ -57,408 +61,342 @@ typedef struct via_texture_object_t *viaTextureObjectPtr;
 #define VIA_FALLBACK_STENCIL                   0x100
 #define VIA_FALLBACK_BLEND_EQ                  0x200
 #define VIA_FALLBACK_BLEND_FUNC                0x400
+#define VIA_FALLBACK_USER_DISABLE              0x800
+#define VIA_FALLBACK_PROJ_TEXTURE              0x1000
+#define VIA_FALLBACK_STIPPLE           0x2000
+
+#define VIA_DMA_BUFSIZ                  4096
+#define VIA_DMA_HIGHWATER               (VIA_DMA_BUFSIZ - 128)
+
+#define VIA_NO_CLIPRECTS 0x1
+
 
-#define VIA_UPLOAD_NONE                        0x0000
-#define VIA_UPLOAD_ALPHATEST           0x0001
-#define VIA_UPLOAD_BLEND               0x0002
-#define VIA_UPLOAD_FOG                         0x0004
-#define VIA_UPLOAD_MASK_ROP            0x0008
-#define VIA_UPLOAD_LINESTIPPLE         0x0010
-#define VIA_UPLOAD_POLYGONSTIPPLE      0x0020
-#define VIA_UPLOAD_DEPTH               0x0040
-#define VIA_UPLOAD_TEXTURE             0x0080
-#define VIA_UPLOAD_STENCIL             0x0100
-#define VIA_UPLOAD_CLIPPING            0x0200
-#define VIA_UPLOAD_DESTBUFFER          0x0400
-#define VIA_UPLOAD_DEPTHBUFFER         0x0800
-#define VIA_UPLOAD_ENABLE              0x0800
-#define VIA_UPLOAD_ALL                         0x1000
-               
 /* Use the templated vertex formats:
  */
 #define TAG(x) via##x
 #include "tnl_dd/t_dd_vertex.h"
 #undef TAG
-#define BUFFER_ALIGNMENT 32
-#define BUFFER_ALIGN_WIDTH1(w, a)   (((w) + ((a) - 1)) & ~((a) - 1))
-#define BUFFER_ALIGN_WIDTH(w, a)    (((w) & ((a) - 1)) ? BUFFER_ALIGN_WIDTH1(w, a) : (w))
-#define BUFFER_ALIGN_ADDRESS(p, a)  ((GLvoid *)(((GLint)(p)) + ((a)-1) & ~((a)-1)))
-#define RightOf 1
-#define LeftOf 2
-#define Down 4
-#define Up 8
-#define S0 16
-#define S1 32
-#define P_MASK 0x0f;
-#define S_MASK 0x30;
-typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
+
+typedef void (*via_tri_func)(struct via_context *, viaVertex *, viaVertex *,
                              viaVertex *);
-typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
-typedef void (*via_point_func)(viaContextPtr, viaVertex *);
-
-typedef struct {
-    drmHandle handle;
-    drmSize size;
-    GLuint offset;
-    GLuint index;
-    GLuint pitch;
-    GLuint bpp;
-    char *map;
-} viaBuffer, *viaBufferPtr;
-
-typedef struct {
-    drmHandle handle;
-    drmSize size;
-    GLuint offset;
-    GLuint index;
-    unsigned char* map;
-} viaDmaBuffer, *viaDmaBufferPtr;
-
-struct via_context_t {
-    GLint refcount;   
-    GLcontext *glCtx;
-    GLcontext *shareCtx;
-    unsigned char* front_base;
-    viaBuffer front;
-    viaBuffer back;
-    viaBuffer depth;
-    GLboolean hasBack;
-    GLboolean hasDepth;
-    GLboolean hasStencil;
-    GLboolean hasAccum;
-    GLuint    depthBits;
-    GLuint    stencilBits;
-    viaDmaBuffer dma[2];
-    viaRegion tex;
+typedef void (*via_line_func)(struct via_context *, viaVertex *, viaVertex *);
+typedef void (*via_point_func)(struct via_context *, viaVertex *);
+
+struct via_buffer {
+   drm_handle_t handle;
+   drmSize size;
+   GLuint offset;
+   GLuint index;
+   GLuint pitch;
+   GLuint bpp;
+   char *map;
+   GLuint orig;                /* The drawing origin, 
+                        * at (drawX,drawY) in screen space.
+                        */
+   char *origMap;
+};
+
+
+#define VIA_MAX_TEXLEVELS      10
+
+struct via_tex_buffer {
+   struct via_tex_buffer *next, *prev;
+   struct via_texture_image *image;
+   GLuint index;
+   GLuint offset;
+   GLuint size;
+   GLuint memType;    
+   unsigned char *bufAddr;
+   GLuint texBase;
+   GLuint lastUsed;
+};
+
+
+
+struct via_texture_image {
+   struct gl_texture_image image;
+   struct via_tex_buffer *texMem;
+   GLint pitchLog2;
+};
+
+struct via_texture_object {
+   struct gl_texture_object obj; /* The "parent" object */
+
+   GLuint texelBytes;
+   GLuint memType;
+
+   GLuint regTexFM;
+   GLuint regTexWidthLog2[2];
+   GLuint regTexHeightLog2[2];
+   GLuint regTexBaseH[4];
+   struct {
+      GLuint baseL;
+      GLuint pitchLog2;
+   } regTexBaseAndPitch[12];
+
+   GLint firstLevel, lastLevel;  /* upload tObj->Image[first .. lastLevel] */
+};              
+
+
+
+struct via_context {
+   GLint refcount;   
+   GLcontext *glCtx;
+   GLcontext *shareCtx;
+
+   struct via_buffer front;
+   struct via_buffer back;
+   struct via_buffer depth;
+   struct via_buffer breadcrumb;
+
+   GLboolean hasBack;
+   GLboolean hasDepth;
+   GLboolean hasStencil;
+   GLboolean hasAccum;
+   GLuint    depthBits;
+   GLuint    stencilBits;
+
+   GLboolean have_hw_stencil;
+   GLuint ClearDepth;
+   GLuint depth_clear_mask;
+   GLuint stencil_clear_mask;
+   GLfloat depth_max;
+   GLfloat polygon_offset_scale;
+
+   GLubyte    *dma;
+   viaRegion tex;
     
-    GLuint isAGP;
+   /* Bit flag to keep 0track of fallbacks.
+    */
+   GLuint Fallback;
 
-    /* Textures
+   /* State for via_tris.c.
     */
-    viaTextureObjectPtr CurrentTexObj[2];
-    struct via_texture_object_t TexObjList;
-    struct via_texture_object_t SwappedOut;
-    memHeap_t *texHeap;
-
-    /* Bit flag to keep 0track of fallbacks.
-     */
-    GLuint Fallback;
-
-    /* Temporaries for translating away float colors:
-     */
-    struct gl_client_array UbyteColor;
-    struct gl_client_array UbyteSecondaryColor;
-
-    /* State for via_vb.c and via_tris.c.
-     */
-    GLuint newState;            /* _NEW_* flags */
-    GLuint setupNewInputs;
-    GLuint setupIndex;
-    GLuint renderIndex;
-    GLmatrix ViewportMatrix;
-    GLenum renderPrimitive;
-    GLenum reducedPrimitive;
-    GLuint hwPrimitive;
-    unsigned char *verts;
-
-    /* drmBufPtr dma_buffer;
+   GLuint newState;            /* _NEW_* flags */
+   GLuint newEmitState;            /* _NEW_* flags */
+   GLuint newRenderState;            /* _NEW_* flags */
+
+   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+   GLuint vertex_attr_count;
+
+   GLuint setupIndex;
+   GLuint renderIndex;
+   GLmatrix ViewportMatrix;
+   GLenum renderPrimitive;
+   GLenum hwPrimitive;
+   unsigned char *verts;
+
+   /* drmBufPtr dma_buffer;
     */
-    unsigned char* dmaAddr;
-    GLuint dmaIndex;
-    GLuint dmaLow;
-    GLuint dmaHigh;
-    GLuint dmaLastPrim;
-    GLboolean useAgp;
+   GLuint dmaLow;
+   GLuint dmaCliprectAddr;
+   GLuint dmaLastPrim;
+   GLboolean useAgp;
    
-    GLboolean uploadCliprects;
 
-    GLuint needUploadAllState;
-    GLuint primitiveRendered;
-    
+   /* Fallback rasterization functions 
+    */
+   via_point_func drawPoint;
+   via_line_func drawLine;
+   via_tri_func drawTri;
 
-    /* Fallback rasterization functions 
-     */
-    via_point_func drawPoint;
-    via_line_func drawLine;
-    via_tri_func drawTri;
-
-    /* Hardware register
-     */
-    GLuint regCmdA;
-    GLuint regCmdA_End;
-    GLuint regCmdB;
-
-    GLuint regEnable;
-    GLuint regHFBBMSKL;
-    GLuint regHROP;
-
-    GLuint regHZWTMD;
-    GLuint regHSTREF;
-    GLuint regHSTMD;
-
-    GLuint regHATMD;
-    GLuint regHABLCsat;
-    GLuint regHABLCop;
-    GLuint regHABLAsat;
-    GLuint regHABLAop;
-    GLuint regHABLRCa;
-    GLuint regHABLRFCa;
-    GLuint regHABLRCbias;
-    GLuint regHABLRCb;
-    GLuint regHABLRFCb;
-    GLuint regHABLRAa;
-    GLuint regHABLRAb;
-    GLuint regHFogLF;
-    GLuint regHFogCL;
-    GLuint regHFogCH;
-
-    GLuint regHLP;
-    GLuint regHLPRF;
-
-    GLuint regHTXnTB_0;
-    GLuint regHTXnMPMD_0;
-    GLuint regHTXnTBLCsat_0;
-    GLuint regHTXnTBLCop_0;
-    GLuint regHTXnTBLMPfog_0;
-    GLuint regHTXnTBLAsat_0;
-    GLuint regHTXnTBLRCb_0;
-    GLuint regHTXnTBLRAa_0;
-    GLuint regHTXnTBLRFog_0;
-    /*=* John Sheng [2003.7.18] texture combine *=*/
-    GLuint regHTXnTBLRCa_0;
-    GLuint regHTXnTBLRCc_0;
-    GLuint regHTXnTBLRCbias_0;
-
-    GLuint regHTXnTB_1;
-    GLuint regHTXnMPMD_1;
-    GLuint regHTXnTBLCsat_1;
-    GLuint regHTXnTBLCop_1;
-    GLuint regHTXnTBLMPfog_1;
-    GLuint regHTXnTBLAsat_1;
-    GLuint regHTXnTBLRCb_1;
-    GLuint regHTXnTBLRAa_1;
-    GLuint regHTXnTBLRFog_1;
-
-    /* Hardware state 
-     */
-    GLuint dirty;             
-    int vertexSize;
-    int vertexStrideShift;
-    GLint lastStamp;
-    GLboolean stippleInHw;
-
-    GLenum TexEnvImageFmt[2];
-    GLuint ClearColor;
-    /* DRI stuff
-     */
-    GLuint needClip;
-    GLframebuffer *glBuffer;
-    GLboolean doPageFlip;
-    /*=* John Sheng [2003.5.31] flip *=*/
-    GLuint currentPage;
-    char *drawMap;               /* draw buffer address in virtual mem */
-    char *readMap;       
-    int drawX;                   /* origin of drawable in draw buffer */
-    int drawY;
-    
-    int drawW;                  
-    int drawH;
-    GLuint saam;
-#ifdef USE_XINERAMA
-    XineramaScreenInfo *xsi;
-#endif
-    int drawXoffSaam;
-    drm_clip_rect_t *pSaamRects;
-    int drawXSaam;
-    int drawYSaam;
-    GLuint numSaamRects;
-    
-    int drawPitch;
-    int readPitch;
-    int drawXoff;
-    GLuint numClipRects;         /* cliprects for that buffer */
-    drm_clip_rect_t *pClipRects;
-
-    int lastSwap;
-    int texAge;
-    int ctxAge;
-    int dirtyAge;
-
-    GLboolean scissor;
-    drm_clip_rect_t drawRect;
-    drm_clip_rect_t scissorRect;
-
-    drmContext hHWContext;
-    drm_hw_lock_t *driHwLock;
-    int driFd;
-#ifndef _SOLO
-    Display *display;
-#endif
+   /* Hardware register
+    */
+   GLuint regCmdA_End;
+   GLuint regCmdB;
+
+   GLuint regEnable;
+   GLuint regHFBBMSKL;
+   GLuint regHROP;
+
+   GLuint regHZWTMD;
+   GLuint regHSTREF;
+   GLuint regHSTMD;
+
+   GLuint regHATMD;
+   GLuint regHABLCsat;
+   GLuint regHABLCop;
+   GLuint regHABLAsat;
+   GLuint regHABLAop;
+   GLuint regHABLRCa;
+   GLuint regHABLRFCa;
+   GLuint regHABLRCbias;
+   GLuint regHABLRCb;
+   GLuint regHABLRFCb;
+   GLuint regHABLRAa;
+   GLuint regHABLRAb;
+   GLuint regHFogLF;
+   GLuint regHFogCL;
+   GLuint regHFogCH;
+
+   GLuint regHLP;
+   GLuint regHLPRF;
+   
+   GLuint regHTXnCLOD[2];
+   GLuint regHTXnTB[2];
+   GLuint regHTXnMPMD[2];
+   GLuint regHTXnTBLCsat[2];
+   GLuint regHTXnTBLCop[2];
+   GLuint regHTXnTBLMPfog[2];
+   GLuint regHTXnTBLAsat[2];
+   GLuint regHTXnTBLRCb[2];
+   GLuint regHTXnTBLRAa[2];
+   GLuint regHTXnTBLRFog[2];
+   GLuint regHTXnTBLRCa[2];
+   GLuint regHTXnTBLRCc[2];
+   GLuint regHTXnTBLRCbias[2];
+   GLuint regHTXnTBC[2];
+   GLuint regHTXnTRAH[2];
+
+   int vertexSize;
+   int hwVertexSize;
+   GLboolean ptexHack;
+   int coloroffset;
+   int specoffset;
+
+   GLint lastStamp;
+
+   GLuint ClearColor;
+   GLuint ClearMask;
+
+   /* DRI stuff
+    */
+   GLboolean doPageFlip;
+
+   struct via_buffer *drawBuffer;
+   struct via_buffer *readBuffer;
+
+   int drawX;                   /* origin of drawable in draw buffer */
+   int drawY;    
+   int drawW;                  
+   int drawH;    
+
+   int drawXoff;               /* drawX is 32byte aligned - this is
+                                * the delta to the real origin, in
+                                * pixel units.
+                                */
+
+   GLuint numClipRects;         /* cliprects for that buffer */
+   drm_clip_rect_t *pClipRects;
+
+   GLboolean scissor;
+   drm_clip_rect_t drawRect;
+   drm_clip_rect_t scissorRect;
+
+   drm_context_t hHWContext;
+   drm_hw_lock_t *driHwLock;
+   int driFd;
+   __DRInativeDisplay *display;
+
+   __DRIdrawablePrivate *driDrawable;
+   __DRIscreenPrivate *driScreen;
+   viaScreenPrivate *viaScreen;
+   drm_via_sarea_t *sarea;
+   volatile GLuint* regMMIOBase;
+   volatile GLuint* pnGEMode;
+   volatile GLuint* regEngineStatus;
+   volatile GLuint* regTranSet;
+   volatile GLuint* regTranSpace;
+   GLuint* agpBase;
+   GLuint drawType;
+
+   GLuint nDoneFirstFlip;
+   GLuint agpFullCount;
+
+   GLboolean clearTexCache;
+   GLboolean thrashing;
+
+   /* Configuration cache
+    */
+   driOptionCache optionCache;
+
+   GLuint vblank_flags;
+   GLuint vbl_seq;
+
+   int64_t swap_ust;
+   int64_t swap_missed_ust;
+
+   GLuint swap_count;
+   GLuint swap_missed_count;
+
+   PFNGLXGETUSTPROC get_ust;
 
-    __DRIdrawablePrivate *driDrawable;
-    __DRIscreenPrivate *driScreen;
-    viaScreenPrivate *viaScreen;
-    drm_via_sarea_t *sarea;
-    volatile GLuint* regMMIOBase;
-    volatile GLuint* pnGEMode;
-    volatile GLuint* regEngineStatus;
-    volatile GLuint* regTranSet;
-    volatile GLuint* regTranSpace;
-    GLuint* agpBase;
-    GLuint drawType;
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    int VQEnable;
+   GLuint pfCurrentOffset;
+   GLboolean allowPageFlip;
+
+   GLuint lastBreadcrumbRead;
+   GLuint lastBreadcrumbWrite;
+   GLuint lastSwap[2];
+   GLuint lastDma;
+   
+   GLuint total_alloc[VIA_MEM_SYSTEM+1];
+
+   struct via_tex_buffer tex_image_list[VIA_MEM_SYSTEM+1];
+   struct via_tex_buffer freed_tex_buffers;
+   
 };
-/*#define DMA_OFFSET 16*/
-#define DMA_OFFSET 32
-/*#define PERFORMANCE_MEASURE*/
-
-extern GLuint VIA_PERFORMANCE;
-
-#ifdef PERFORMANCE_MEASURE
-#define HASH_TABLE_SIZE 1000
-#define HASH_TABLE_DEPTH 10
-typedef struct {
-    char func[50];
-    GLuint count;
-} hash_element;
-extern hash_element hash_table[HASH_TABLE_SIZE][HASH_TABLE_DEPTH];
-#define P_M                                                                      \
-    do {                                                                         \
-       GLuint h_index,h_depth;                                                  \
-       h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE);             \
-       for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) {                \
-           if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) {             \
-               sprintf(hash_table[h_index][h_depth].func, "%s", __FUNCTION__);  \
-               hash_table[h_index][h_depth].count++;                            \
-               break;                                                           \
-           }                                                                    \
-           else if (!strcmp(hash_table[h_index][h_depth].func, __FUNCTION__)) {  \
-               hash_table[h_index][h_depth].count++;                            \
-               break;                                                           \
-           }                                                                    \
-       }                                                                        \
-    } while (0)
-
-#define P_M_X                                                                          \
-    do {                                                                               \
-       GLuint h_index,h_depth;                                                         \
-       char str[80];                                                                   \
-       strcpy(str, __FUNCTION__);                                                      \
-       h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE);                    \
-       for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) {                      \
-           if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) {                   \
-               sprintf(hash_table[h_index][h_depth].func, "%s_X", __FUNCTION__);       \
-               hash_table[h_index][h_depth].count++;                                   \
-               break;                                                                  \
-           }                                                                           \
-           else if (!strcmp(hash_table[h_index][h_depth].func, strcat(str, "_X"))) {   \
-               hash_table[h_index][h_depth].count++;                                   \
-               break;                                                                  \
-           }                                                                           \
-       }                                                                               \
-    } while (0)
-
-#define P_M_R                                                                                                                  \
-    do {                                                                                                                       \
-       GLuint h_size, h_depth;                                                                                                 \
-       for (h_size = 0; h_size < HASH_TABLE_SIZE; h_size++) {                                                                  \
-           for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) {                                                          \
-               if (hash_table[h_size][h_depth].count) {                                                                        \
-                   fprintf(stderr, "func:%s count:%d\n", hash_table[h_size][h_depth].func, hash_table[h_size][h_depth].count); \
-               }                                                                                                               \
-           }                                                                                                                   \
-       }                                                                                                                       \
-    } while (0)
-#else /* PERFORMANCE_MEASURE */
-#define P_M {}
-#define P_M_X {}
-#define P_M_R {}
-#endif
 
-#define VIA_CONTEXT(ctx)   ((viaContextPtr)(ctx->DriverCtx))
 
-#define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
-#define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
+
+#define VIA_CONTEXT(ctx)   ((struct via_context *)(ctx->DriverCtx))
+
 
 
 /* Lock the hardware and validate our state.  
  */
-/*
-#define LOCK_HARDWARE(vmesa)                                \
-    do {                                                    \
-        char __ret = 0;                                     \
-        DRM_CAS(vmesa->driHwLock, vmesa->hHWContext,        \
-            (DRM_LOCK_HELD|vmesa->hHWContext), __ret);      \
-        if (__ret)                                          \
-            viaGetLock(vmesa, 0);                           \
-    } while (0)
-*/
-/*=* John Sheng [2003.6.20] fix pci *=*/
-/*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
 #define LOCK_HARDWARE(vmesa)                                   \
-    if(1)                                              \
        do {                                                    \
            char __ret = 0;                                     \
            DRM_CAS(vmesa->driHwLock, vmesa->hHWContext,        \
                (DRM_LOCK_HELD|vmesa->hHWContext), __ret);      \
            if (__ret)                                          \
                viaGetLock(vmesa, 0);                           \
-       } while (0);                                            \
-    else                                                        \
-       viaLock(vmesa, 0)
-       
+       } while (0)
 
-/*
-#define LOCK_HARDWARE(vmesa)                                   \
-    viaLock(vmesa, 0);                           
-*/
 
 /* Release the kernel lock.
  */
-/*
-#define UNLOCK_HARDWARE(vmesa)                                  \
-    DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
-*/
-/*=* John Sheng [2003.6.20] fix pci *=*/
-/*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
 #define UNLOCK_HARDWARE(vmesa)                                         \
-    if(1)                                                      \
-       DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);  \
-    else                                                               \
-       viaUnLock(vmesa, 0);                            
-/*     
-#define UNLOCK_HARDWARE(vmesa)                                 \
-    viaUnLock(vmesa, 0);
-*/
-#define WAIT_IDLE                                                              \
-    while (1) {                                                                \
-       if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000)     \
-           break;                                                              \
-    }
-       
-#define LOCK_HARDWARE_QUIESCENT(vmesa)          \
-    do {                                        \
-        LOCK_HARDWARE(vmesa);                   \
-        viaRegetLockQuiescent(vmesa);           \
-    } while (0)
+       DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);  
 
+       
 
 extern GLuint VIA_DEBUG;
-extern GLuint DRAW_FRONT;
-extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
-extern void viaLock(viaContextPtr vmesa, GLuint flags);
-extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
-extern void viaEmitHwStateLocked(viaContextPtr vmesa);
-extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
-extern void viaEmitDrawingRectangle(viaContextPtr vmesa);
-extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
-extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
+
+#define DEBUG_TEXTURE  0x1
+#define DEBUG_STATE    0x2
+#define DEBUG_IOCTL    0x4
+#define DEBUG_PRIMS    0x8
+#define DEBUG_VERTS    0x10
+#define DEBUG_FALLBACKS        0x20
+#define DEBUG_VERBOSE  0x40
+#define DEBUG_DRI       0x80
+#define DEBUG_DMA       0x100
+#define DEBUG_SANITY    0x200
+#define DEBUG_SYNC      0x400
+#define DEBUG_SLEEP     0x800
+#define DEBUG_PIXEL     0x1000
+#define DEBUG_2D        0x2000
+
+
+extern void viaGetLock(struct via_context *vmesa, GLuint flags);
+extern void viaLock(struct via_context *vmesa, GLuint flags);
+extern void viaUnLock(struct via_context *vmesa, GLuint flags);
+extern void viaEmitHwStateLocked(struct via_context *vmesa);
+extern void viaEmitScissorValues(struct via_context *vmesa, int box_nr, int emit);
+extern void viaXMesaSetBackClipRects(struct via_context *vmesa);
+extern void viaXMesaSetFrontClipRects(struct via_context *vmesa);
 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
-extern void viaXMesaWindowMoved(viaContextPtr vmesa);
+extern void viaXMesaWindowMoved(struct via_context *vmesa);
 
-#define SUBPIXEL_X -.5
-#define SUBPIXEL_Y -.5
+extern GLboolean viaTexCombineState(struct via_context *vmesa,
+                                   const struct gl_tex_env_combine_state * combine, 
+                                   unsigned unit );
+
+/* Via hw already adjusted for GL pixel centers:
+ */
+#define SUBPIXEL_X 0
+#define SUBPIXEL_Y 0
 
 /* TODO XXX _SOLO temp defines to make code compilable */
 #ifndef GLX_PBUFFER_BIT