Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / drivers / dri / r128 / r128_state.c
index 80771ae29bab446bfe20ade926d1b3dca94f1600..e476afa5d828a982d56173102e5cb2e6f0aeace7 100644 (file)
@@ -44,7 +44,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "enums.h"
 #include "colormac.h"
 #include "swrast/swrast.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "swrast_setup/swrast_setup.h"
 
@@ -260,9 +260,9 @@ r128DDStencilFuncSeparate( GLcontext *ctx, GLenum face, GLenum func,
                            GLint ref, GLuint mask )
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
-   GLuint refmask = ((ctx->Stencil.Ref[0] << 0) |
-                    (ctx->Stencil.ValueMask[0] << 16) |
-                    (ctx->Stencil.WriteMask[0] << 24)); 
+   GLuint refmask = (((ctx->Stencil.Ref[0] & 0xff) << 0) |
+                    ((ctx->Stencil.ValueMask[0] & 0xff) << 16) |
+                    ((ctx->Stencil.WriteMask[0] & 0xff) << 24)); 
    GLuint z = rmesa->setup.z_sten_cntl_c;
 
    z &= ~R128_STENCIL_TEST_MASK;
@@ -307,9 +307,9 @@ static void
 r128DDStencilMaskSeparate( GLcontext *ctx, GLenum face, GLuint mask )
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
-   GLuint refmask = ((ctx->Stencil.Ref[0] << 0) |
-                    (ctx->Stencil.ValueMask[0] << 16) |
-                    (ctx->Stencil.WriteMask[0] << 24)); 
+   GLuint refmask = (((ctx->Stencil.Ref[0] & 0xff) << 0) |
+                    ((ctx->Stencil.ValueMask[0] & 0xff) << 16) |
+                    ((ctx->Stencil.WriteMask[0] & 0xff) << 24)); 
 
    if ( rmesa->setup.sten_ref_mask_c != refmask ) {
       rmesa->setup.sten_ref_mask_c = refmask;
@@ -322,7 +322,6 @@ static void r128DDStencilOpSeparate( GLcontext *ctx, GLenum face, GLenum fail,
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
    GLuint z = rmesa->setup.z_sten_cntl_c;
-   GLboolean ok = 1;
 
    if (!( ctx->Visual.stencilBits > 0 && ctx->Visual.depthBits == 24 ))
       return;
@@ -336,11 +335,9 @@ static void r128DDStencilOpSeparate( GLcontext *ctx, GLenum face, GLenum fail,
       break;
    case GL_ZERO:
       z |= R128_STENCIL_S_FAIL_ZERO;
-      ok = 0; /* Hardware bug?  ZERO maps to KEEP */
       break;
    case GL_REPLACE:
       z |= R128_STENCIL_S_FAIL_REPLACE;
-      ok = 0; /* Hardware bug?  REPLACE maps to KEEP */
       break;
    case GL_INCR:
       z |= R128_STENCIL_S_FAIL_INC;
@@ -350,14 +347,18 @@ static void r128DDStencilOpSeparate( GLcontext *ctx, GLenum face, GLenum fail,
       break;
    case GL_INVERT:
       z |= R128_STENCIL_S_FAIL_INV;
-      ok = 0; /* Hardware bug?  INV maps to ZERO */
+      break;
+   case GL_INCR_WRAP:
+      z |= R128_STENCIL_S_FAIL_INC_WRAP;
+      break;
+   case GL_DECR_WRAP:
+      z |= R128_STENCIL_S_FAIL_DEC_WRAP;
       break;
    }
 
    switch ( ctx->Stencil.ZFailFunc[0] ) {
    case GL_KEEP:
       z |= R128_STENCIL_ZFAIL_KEEP;
-      ok = 0; /* Hardware bug?  KEEP maps to ZERO */
       break;
    case GL_ZERO:
       z |= R128_STENCIL_ZFAIL_ZERO;
@@ -373,14 +374,18 @@ static void r128DDStencilOpSeparate( GLcontext *ctx, GLenum face, GLenum fail,
       break;
    case GL_INVERT:
       z |= R128_STENCIL_ZFAIL_INV;
-      ok = 0; /* Hardware bug?  INV maps to ZERO */
+      break;
+   case GL_INCR_WRAP:
+      z |= R128_STENCIL_ZFAIL_INC_WRAP;
+      break;
+   case GL_DECR_WRAP:
+      z |= R128_STENCIL_ZFAIL_DEC_WRAP;
       break;
    }
 
    switch ( ctx->Stencil.ZPassFunc[0] ) {
    case GL_KEEP:
       z |= R128_STENCIL_ZPASS_KEEP;
-      ok = 0; /* Hardware bug?  KEEP maps to ZERO */
       break;
    case GL_ZERO:
       z |= R128_STENCIL_ZPASS_ZERO;
@@ -393,22 +398,18 @@ static void r128DDStencilOpSeparate( GLcontext *ctx, GLenum face, GLenum fail,
       break;
    case GL_DECR:
       z |= R128_STENCIL_ZPASS_DEC;
-      ok = 0; /* Hardware bug?  DEC maps to INCR_WRAP */
       break;
    case GL_INVERT:
       z |= R128_STENCIL_ZPASS_INV;
-      ok = 0; /* Hardware bug?  INV maps to ZERO */
+      break;
+   case GL_INCR_WRAP:
+      z |= R128_STENCIL_ZPASS_INC_WRAP;
+      break;
+   case GL_DECR_WRAP:
+      z |= R128_STENCIL_ZPASS_DEC_WRAP;
       break;
    }
 
-   /* XXX: Now that we know whether we can do the given funcs successfully
-    * (according to testing done with a modified stencilwrap test), go
-    * ahead and drop that knowledge on the floor.  While fallbacks remain
-    * broken, they make the situation even worse (in test apps, at least) than
-    * failing in just the stencil part.
-    */
-   /*FALLBACK( rmesa, R128_FALLBACK_STENCIL, !ok );*/
-
    if ( rmesa->setup.z_sten_cntl_c != z ) {
       rmesa->setup.z_sten_cntl_c = z;
       rmesa->dirty |= R128_UPLOAD_CONTEXT;
@@ -598,8 +599,26 @@ static void r128UpdateClipping( GLcontext *ctx )
       x2 += drawable->x;
       y2 += drawable->y;
 
-      rmesa->setup.sc_top_left_c     = ((y1 << 16) | x1);
-      rmesa->setup.sc_bottom_right_c = ((y2 << 16) | x2);
+      /* Clamp values to screen to avoid wrapping problems */
+      if ( x1 < 0 )
+         x1 = 0;
+      else if ( x1 >= rmesa->driScreen->fbWidth )
+         x1 = rmesa->driScreen->fbWidth - 1;
+      if ( y1 < 0 )
+         y1 = 0;
+      else if ( y1 >= rmesa->driScreen->fbHeight )
+         y1 = rmesa->driScreen->fbHeight - 1;
+      if ( x2 < 0 )
+         x2 = 0;
+      else if ( x2 >= rmesa->driScreen->fbWidth )
+         x2 = rmesa->driScreen->fbWidth - 1;
+      if ( y2 < 0 )
+         y2 = 0;
+      else if ( y2 >= rmesa->driScreen->fbHeight )
+         y2 = rmesa->driScreen->fbHeight - 1;
+
+      rmesa->setup.sc_top_left_c     = (((y1 & 0x3FFF) << 16) | (x1 & 0x3FFF));
+      rmesa->setup.sc_bottom_right_c = (((y2 & 0x3FFF) << 16) | (x2 & 0x3FFF));
 
       rmesa->dirty |= R128_UPLOAD_CONTEXT;
    }
@@ -797,8 +816,8 @@ static void r128UpdateWindow( GLcontext *ctx )
    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][0];
    driRenderbuffer *drb = (driRenderbuffer *) rb;
 
-   rmesa->setup.window_xy_offset = ((y << R128_WINDOW_Y_SHIFT) |
-                                   (x << R128_WINDOW_X_SHIFT));
+   rmesa->setup.window_xy_offset = (((y & 0xFFF) << R128_WINDOW_Y_SHIFT) |
+                                   ((x & 0xFFF) << R128_WINDOW_X_SHIFT));
 
    rmesa->setup.dst_pitch_offset_c = (((drb->flippedPitch/8) << 21) |
                                       (drb->flippedOffset >> 5));
@@ -1121,6 +1140,15 @@ void r128EmitHwStateLocked( r128ContextPtr rmesa )
                        R128_UPLOAD_WINDOW |
                        R128_UPLOAD_CORE) ) {
       memcpy( &sarea->context_state, regs, sizeof(sarea->context_state) );
+      
+      if( rmesa->dirty & R128_UPLOAD_CONTEXT )
+      {
+         /* One possible side-effect of uploading a new context is the
+          * setting of the R128_GMC_AUX_CLIP_DIS bit, which causes all
+          * auxilliary cliprects to be disabled. So the next command must
+          * upload them again. */
+         rmesa->dirty |= R128_UPLOAD_CLIPRECTS;
+      }
    }
 
    if ( (rmesa->dirty & R128_UPLOAD_TEX0) && t0 ) {
@@ -1206,7 +1234,10 @@ void r128DDUpdateHWState( GLcontext *ctx )
         r128UpdateMasks( ctx );
 
       if ( new_state & R128_NEW_WINDOW )
+      {
         r128UpdateWindow( ctx );
+        r128CalcViewport( ctx );
+      }
 
       if ( rmesa->NewGLState & _NEW_TEXTURE ) {
         r128UpdateTextureState( ctx );
@@ -1219,7 +1250,7 @@ static void r128DDInvalidateState( GLcontext *ctx, GLuint new_state )
 {
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
-   _ac_InvalidateState( ctx, new_state );
+   _vbo_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
    R128_CONTEXT(ctx)->NewGLState |= new_state;
 }
@@ -1403,19 +1434,4 @@ void r128DDInitStateFuncs( GLcontext *ctx )
 
    ctx->Driver.DepthRange               = r128DepthRange;
    ctx->Driver.Viewport                 = r128Viewport;
-
-   /* Pixel path fallbacks.
-    */
-   ctx->Driver.Accum = _swrast_Accum;
-   ctx->Driver.Bitmap = _swrast_Bitmap;
-   ctx->Driver.CopyPixels = _swrast_CopyPixels;
-   ctx->Driver.DrawPixels = _swrast_DrawPixels;
-   ctx->Driver.ReadPixels = _swrast_ReadPixels;
-
-   /* Swrast hooks for imaging extensions:
-    */
-   ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
-   ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
-   ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-   ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
 }