Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / sis / sis_context.h
index b6b403b51534799f07aed5dc5334bf157e1feefe..4179ee081a7572d3ce79d783fc204c44c6bb98a6 100644 (file)
@@ -24,7 +24,6 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
-/* $XFree86$ */
 
 /*
  * Authors:
@@ -35,12 +34,16 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _sis_ctx_h_
 #define _sis_ctx_h_
 
-#include "context.h"
+#include "main/context.h"
 #include "dri_util.h"
+#include "drm.h"
+#include "drm_sarea.h"
 #include "xmlconfig.h"
+#include "tnl/t_vertex.h"
 
 #include "sis_screen.h"
-#include "sis_common2.h"
+#include "sis_reg.h"
+#include "sis6326_reg.h"
 #include "sis_dri.h"
 
 /* for GLboolean */
@@ -62,7 +65,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define SIS_FALLBACK_TEXENV1           0x0010
 #define SIS_FALLBACK_DRAW_BUFFER       0x0020
 #define SIS_FALLBACK_STENCIL           0x0040
-#define SIS_FALLBACK_FORCE             0x8000
+#define SIS_FALLBACK_WRITEMASK         0x0080
+#define SIS_FALLBACK_DISABLE           0x0100
 
 /* Flags for hardware state that needs to be updated */
 #define GFLAG_ENABLESETTING            0x00000001
@@ -112,7 +116,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define SUBPIXEL_X  (-0.5F)
 #define SUBPIXEL_Y  (-0.5F)
 
+#define SIS_MAX_TEXTURE_SIZE 2048
+#define SIS_MAX_TEXTURES 2
 #define SIS_MAX_TEXTURE_LEVELS         11
+#define SIS_MAX_FRAME_LENGTH 3
 
 typedef struct {
    GLubyte *Data;              /* Pointer to texture in offscreen */
@@ -126,7 +133,8 @@ typedef struct sis_tex_obj {
    sisTexImage image[SIS_MAX_TEXTURE_LEVELS];  /* Image data for each mipmap
                                                 * level */
    GLenum format;              /* One of GL_ALPHA, GL_INTENSITY, GL_LUMINANCE,
-                                * GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA */
+                                * GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
+                                * MESA_YCBCR */
    GLint hwformat;              /* One of the TEXEL_ defines */
    GLint numImages;             /* Number of images loaded into .image */
 } sisTexObj, *sisTexObjPtr;
@@ -140,6 +148,7 @@ typedef struct __GLSiSTextureRec
   GLint hwTextureMip;
   GLint hwTextureClrHigh;
   GLint hwTextureClrLow;
+  GLint hwTexWidthHeight;      /* 6326: Texture Blending Setting */
   GLint hwTextureBorderColor;
 
   GLint texOffset0;
@@ -199,6 +208,7 @@ typedef struct __GLSiSHardwareRec
 
   GLint hwTexEnvColor;         /* Texture Blending Setting */
 
+  GLint hwTexBlendSet;         /* 6326 */
   GLint hwTexBlendColor0;
   GLint hwTexBlendColor1;
   GLint hwTexBlendAlpha0;
@@ -228,6 +238,19 @@ typedef void (*sis_line_func)( sisContextPtr,
 typedef void (*sis_point_func)( sisContextPtr,
                                sisVertex * );
 
+/**
+ * Derived from gl_renderbuffer.
+ */
+struct sis_renderbuffer {
+   struct gl_renderbuffer Base;  /* must be first! */
+   drmSize size;
+   GLuint offset;
+   void *handle;
+   GLuint pitch;
+   GLuint bpp;
+   char *map;
+};
+
 /* Device dependent context state */
 
 struct sis_context
@@ -235,26 +258,34 @@ struct sis_context
   /* This must be first in this structure */
   GLcontext *glCtx;
 
+  /* Vertex state */
+  GLuint vertex_size;
+  struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+  GLuint vertex_attr_count;
+  char *verts;                 /* points to tnl->clipspace.vertex_buf */
+
+  /* Vertex buffer (in system memory or AGP) state. */
+  unsigned char *vb;           /* Beginning of vertex buffer */
+  unsigned char *vb_cur;       /* Current write location in vertex buffer */
+  unsigned char *vb_last;      /* Last written location in vertex buffer */
+  unsigned char *vb_end;       /* End of vertex buffer */
+  void *vb_agp_handle;
+  GLuint vb_agp_offset;
+  GLboolean using_agp;
+  GLint coloroffset;           /* Offset in vertex format of current color */
+  GLint specoffset;            /* Offset in vertex format of specular color */
+
   GLuint NewGLState;
   GLuint Fallback;
-  GLuint SetupIndex;
-  GLuint SetupNewInputs;
   GLuint RenderIndex;
   GLfloat hw_viewport[16];
   GLfloat depth_scale;
-  GLuint vertex_size;
-  GLuint vertex_stride_shift;
-  GLuint vertex_format;
-  GLuint num_verts;
-  GLubyte *verts;              
 
   unsigned int virtualX, virtualY;
   unsigned int bytesPerPixel;
   unsigned char *IOBase;
   unsigned char *FbBase;
   unsigned int displayWidth;
-  unsigned int frontOffset;
-  unsigned int frontPitch;
 
   /* HW RGBA layout */
   unsigned int redMask, greenMask, blueMask, alphaMask;
@@ -286,15 +317,6 @@ struct sis_context
   unsigned char *AGPBase;
   unsigned int AGPAddr;
   
-  /* AGP Command Buffer */
-  /* TODO: use Global variables */                                                                                
-
-  unsigned char *AGPCmdBufBase;
-  GLint AGPCmdBufAddr;
-  unsigned int AGPCmdBufSize;
-  GLint *pAGPCmdBufNext;
-  GLboolean AGPCmdModeEnabled;
-
   /* register 0x89F4 */
   GLint AGPParseSet;
 
@@ -304,16 +326,14 @@ struct sis_context
   __GLSiSHardware prev, current;
 
   int Chipset;
+  GLboolean is6326;
 
   GLint drawableID;
 
-  /* SGRAM block write */
-  GLboolean blockWrite;
-
   GLint GlobalFlag;
+  DECLARE_RENDERINPUTS(last_tcl_state_bitset);
 
   /* Stereo */
-  GLboolean isFullScreen;
   GLboolean useStereo;
   GLboolean stereoEnabled;
   int stereo_drawIndex;
@@ -331,29 +351,21 @@ struct sis_context
   /* Front/back/depth buffer info */
   GLuint width, height;                        /* size of buffers */
   GLint bottom;                                /* used for FLIP macro */
-  GLvoid *backbuffer;
-  unsigned int backOffset;
-  unsigned int backPitch;
-  GLvoid *depthbuffer;
-  unsigned int depthOffset;
-  unsigned int depthPitch;
-  void *zbFree, *bbFree;               /* Cookies for freeing buffers */
-  ENGPACKET zClearPacket, cbClearPacket;
-
-  /* Drawable, cliprect and scissor information
-   */
-  GLint drawOffset, drawPitch;
-  GLint readOffset, readPitch;
+  /* XXX These don't belong here.  They should be per-drawable state. */
+  struct sis_renderbuffer front;
+  struct sis_renderbuffer back;
+  struct sis_renderbuffer depth;
+  struct sis_renderbuffer stencil; /* mirrors depth */
 
   /* Mirrors of some DRI state
    */
-  __DRIcontextPrivate  *driContext;    /* DRI context */
-  __DRIscreenPrivate   *driScreen;     /* DRI screen */
-  __DRIdrawablePrivate *driDrawable;   /* DRI drawable bound to this ctx */
+  __DRIcontext *driContext;    /* DRI context */
+  __DRIscreen  *driScreen;     /* DRI screen */
+  __DRIdrawable        *driDrawable;   /* DRI drawable bound to this ctx */
 
   unsigned int lastStamp;              /* mirror driDrawable->lastStamp */
 
-  drmContext hHWContext;
+  drm_context_t hHWContext;
   drm_hw_lock_t *driHwLock;
 
   sisScreenPtr sisScreen;              /* Screen private DRI data */
@@ -361,6 +373,7 @@ struct sis_context
 
    /* Configuration cache */
    driOptionCache optionCache;
+    GLint texture_depth;
 };
 
 #define SIS_CONTEXT(ctx)               ((sisContextPtr)(ctx->DriverCtx))
@@ -381,18 +394,33 @@ struct sis_context
 
 #define MMIO(reg, value) \
 {\
-  *(GLint *)(GET_IOBase(smesa) + (reg)) = value; \
+   *(volatile GLint *)(smesa->IOBase + (reg)) = value;                 \
 }
 
 #define MMIO_READ(reg) *(volatile GLint *)(smesa->IOBase + (reg))
 #define MMIO_READf(reg) *(volatile GLfloat *)(smesa->IOBase + (reg))
 
+#if defined(__i386__) || defined(__x86_64__)
+#define MMIO_WMB()     __asm __volatile("" : : : "memory")
+#elif defined(__ia64__)
+#define MMIO_WMB()     __asm __volatile("mf" : : : "memory")
+#else
+#error platform needs WMB
+#endif
+
 #define mEndPrimitive()  \
 {       \
-  *(GET_IOBase(smesa) + REG_3D_EndPrimitiveList) = 0xFF;   \
-  *(GLint *)(GET_IOBase(smesa) + 0x8b60) = (GLint)(-1); \
+   *(volatile GLubyte *)(smesa->IOBase + REG_3D_EndPrimitiveList) = 0xff; \
+   *(volatile GLuint *)(smesa->IOBase + 0x8b60) = 0xffffffff;          \
 }
 
+#define sis_fatal_error(...)                                           \
+do {                                                                   \
+       fprintf(stderr, "[%s:%d]:", __FILE__, __LINE__);                \
+       fprintf(stderr, __VA_ARGS__);                                   \
+       exit(-1);                                                       \
+} while (0)
+
 /* Lock required */
 #define mWait3DCmdQueue(wLen)                                          \
 /* Update the mirrored queue pointer if it doesn't indicate enough space */ \
@@ -411,15 +439,18 @@ enum _sis_verbose {
 };
 
 extern GLboolean sisCreateContext( const __GLcontextModes *glVisual,
-                                  __DRIcontextPrivate *driContextPriv,
+                                  __DRIcontext *driContextPriv,
                                    void *sharedContextPrivate );
-extern void sisDestroyContext( __DRIcontextPrivate * );
+extern void sisDestroyContext( __DRIcontext * );
 
-extern GLboolean sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
-                                  __DRIdrawablePrivate *driDrawPriv,
-                                  __DRIdrawablePrivate *driReadPriv );
+void sisReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer,
+                          GLuint width, GLuint height);
 
-extern GLboolean sisUnbindContext( __DRIcontextPrivate *driContextPriv );
+extern GLboolean sisMakeCurrent( __DRIcontext *driContextPriv,
+                                  __DRIdrawable *driDrawPriv,
+                                  __DRIdrawable *driReadPriv );
+
+extern GLboolean sisUnbindContext( __DRIcontext *driContextPriv );
 
 void WaitEngIdle (sisContextPtr smesa);
 void Wait2DEngIdle (sisContextPtr smesa);
@@ -428,7 +459,20 @@ void WaitingFor3dIdle(sisContextPtr smesa, int wLen);
 /* update to hw */
 extern void sis_update_texture_state( sisContextPtr smesa );
 extern void sis_update_render_state( sisContextPtr smesa );
+extern void sis6326_update_texture_state( sisContextPtr smesa );
+extern void sis6326_update_render_state( sisContextPtr smesa );
 
-void sis_fatal_error (void);
+/* ================================================================
+ * Debugging:
+ */
+#define DO_DEBUG               1
 
+#if DO_DEBUG
+extern int SIS_DEBUG;
+#else
+#define SIS_DEBUG              0
 #endif
+
+#define DEBUG_FALLBACKS                0x01
+
+#endif /* _sis_ctx_h_ */