mesa: lift default symlinks target into Makefile.template
[mesa.git] / src / mesa / drivers / dri / sis / sis_clear.c
index 2506cd5a37bc982ffba4a6dcfa99cf24184440f1..323383da62a9d011c7d15453ba4c15a1173c427c 100644 (file)
@@ -18,13 +18,12 @@ 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, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP 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.
 
 **************************************************************************/
-/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_clear.c,v 1.5 2000/09/26 15:56:48 tsi Exp $ */
 
 /*
  * Authors:
@@ -35,14 +34,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sis_context.h"
 #include "sis_state.h"
 #include "sis_lock.h"
-#include "macros.h"
+
 #include "swrast/swrast.h"
+#include "main/macros.h"
 
-#if 0
 static GLbitfield sis_3D_Clear( GLcontext * ctx, GLbitfield mask,
                                GLint x, GLint y, GLint width,
                                GLint height );
-#endif
 static void sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x,
                                    GLint y, GLint width, GLint height );
 static void sis_clear_z_stencil_buffer( GLcontext * ctx,
@@ -55,7 +53,7 @@ set_color_pattern( sisContextPtr smesa, GLubyte red, GLubyte green,
                   GLubyte blue, GLubyte alpha )
 {
    /* XXX only RGB565 and ARGB8888 */
-   switch (GET_ColorFormat(smesa))
+   switch (smesa->colorFormat)
    {
    case DST_FORMAT_ARGB_8888:
       smesa->clearColorPattern = (alpha << 24) +
@@ -67,7 +65,7 @@ set_color_pattern( sisContextPtr smesa, GLubyte red, GLubyte green,
       smesa->clearColorPattern |= smesa->clearColorPattern << 16;
       break;
    default:
-      assert(0);
+      sis_fatal_error("Bad dst color format\n");
    }
 }
 
@@ -76,82 +74,76 @@ sisUpdateZStencilPattern( sisContextPtr smesa, GLclampd z, GLint stencil )
 {
    GLuint zPattern;
 
-   if (z <= 0.0f)
-      zPattern = 0x0;
-   else if (z >= 1.0f)
-      zPattern = 0xFFFFFFFF;
-   else
-      zPattern = doFPtoFixedNoRound( z, 32 );
-
    switch (smesa->zFormat)
    {
    case SiS_ZFORMAT_Z16:
-      zPattern = zPattern >> 16;
+      CLAMPED_FLOAT_TO_USHORT(zPattern, z);
       zPattern |= zPattern << 16;
       break;
    case SiS_ZFORMAT_S8Z24:
-      zPattern = zPattern >> 8;
+      zPattern = FLOAT_TO_UINT(z) >> 8;
       zPattern |= stencil << 24;
       break;
    case SiS_ZFORMAT_Z32:
+      zPattern = FLOAT_TO_UINT(z);
       break;
    default:
-      assert(0);
+      sis_fatal_error("Bad Z format\n");
    }
    smesa->clearZStencilPattern = zPattern;
 }
 
 void
-sisDDClear( GLcontext * ctx, GLbitfield mask, GLboolean all,
-           GLint x, GLint y, GLint width, GLint height )
+sisDDClear( GLcontext * ctx, GLbitfield mask )
 {
-  sisContextPtr smesa = SIS_CONTEXT(ctx);
+   sisContextPtr smesa = SIS_CONTEXT(ctx);
 
-  GLint x1, y1, width1, height1;
+   GLint x1, y1, width1, height1;
 
-   if (all) {
-      GLframebuffer *buffer = ctx->DrawBuffer;
+   /* get region after locking: */
+   x1 = ctx->DrawBuffer->_Xmin;
+   y1 = ctx->DrawBuffer->_Ymin;
+   width1 = ctx->DrawBuffer->_Xmax - x1;
+   height1 = ctx->DrawBuffer->_Ymax - y1;
+   y1 = Y_FLIP(y1 + height1 - 1);
 
-      x1 = 0;
-      y1 = 0;
-      width1 = buffer->Width;
-      height1 = buffer->Height;
-   } else {
-      x1 = x;
-      y1 = Y_FLIP(y+height-1);
-      width1 = width;            
-      height1 = height;
-   }
+   /* Mask out any non-existent buffers */
+   if (ctx->Visual.depthBits == 0 || !ctx->Depth.Mask)
+      mask &= ~BUFFER_BIT_DEPTH;
+   if (ctx->Visual.stencilBits == 0)
+      mask &= ~BUFFER_BIT_STENCIL;
 
    LOCK_HARDWARE();
 
-#if 0
-   /* The 3d clear code is disabled because it appears to be slower, even
-    * in the case of being requested to clear Z and color buffers at the
-    * same time.
+   /* The 3d clear code is use for masked clears because apparently the SiS
+    * 300-series can't do write masks for 2d blits.  3d isn't used in general
+    * because it's slower, even in the case of clearing multiple buffers.
     */
-   if (mask & (DD_BACK_LEFT_BIT | DD_DEPTH_BIT | DD_STENCIL_BIT))
+   /* XXX: Appears to be broken with stencil. */
+   if ((smesa->current.hwCapEnable2 & (MASK_AlphaMaskWriteEnable |
+      MASK_ColorMaskWriteEnable) &&
+      (mask & (BUFFER_BIT_BACK_LEFT | BUFFER_BIT_FRONT_LEFT)) != 0) ||
+      ((ctx->Stencil.WriteMask[0] & 0xff) != 0xff && 
+       (mask & BUFFER_BIT_STENCIL) != 0) )
    {
-      /* only Clear either depth or stencil buffer */ 
       mask = sis_3D_Clear( ctx, mask, x1, y1, width1, height1 );
    }
-#endif
 
-   if ( mask & DD_FRONT_LEFT_BIT || mask & DD_BACK_LEFT_BIT) {
+   if ( mask & BUFFER_BIT_FRONT_LEFT || mask & BUFFER_BIT_BACK_LEFT) {
       sis_clear_color_buffer( ctx, mask, x1, y1, width1, height1 );
-      mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
+      mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT);
    }
 
-   if (mask & (DD_DEPTH_BIT | DD_STENCIL_BIT)) {
-      if (smesa->depthbuffer != NULL)
+   if (mask & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
+      if (smesa->depth.offset != 0)
          sis_clear_z_stencil_buffer( ctx, mask, x1, y1, width1, height1 );
-      mask &= ~(DD_DEPTH_BIT | DD_STENCIL_BIT);
+      mask &= ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
    }
 
    UNLOCK_HARDWARE();
 
    if (mask != 0)
-      _swrast_Clear( ctx, mask, all, x1, y1, width, height );
+      _swrast_Clear( ctx, mask);
 }
 
 
@@ -185,7 +177,6 @@ sisDDClearStencil( GLcontext * ctx, GLint s )
    sisUpdateZStencilPattern( smesa, ctx->Depth.Clear, s );
 }
 
-#if 0
 static GLbitfield
 sis_3D_Clear( GLcontext * ctx, GLbitfield mask,
              GLint x, GLint y, GLint width, GLint height )
@@ -197,31 +188,29 @@ sis_3D_Clear( GLcontext * ctx, GLbitfield mask,
    float left, top, right, bottom, zClearVal;
    GLboolean bClrColor, bClrDepth, bClrStencil;
    GLint dwPrimitiveSet;
-   GLint dwEnable1 = 0, dwEnable2 = 0, dwDepthMask = 0, dwSten1 = 0, dwSten2 = 0;
+   GLint dwEnable1 = 0, dwEnable2 = MASK_ColorMaskWriteEnable;
+   GLint dwDepthMask = 0, dwSten1 = 0, dwSten2 = 0;
    GLint dirtyflags = GFLAG_ENABLESETTING | GFLAG_ENABLESETTING2 |
       GFLAG_CLIPPING | GFLAG_DESTSETTING;
-   
    int count;
-   XF86DRIClipRectPtr pExtents;
+   drm_clip_rect_t *pExtents;
 
-   bClrColor = ((mask & DD_BACK_LEFT_BIT) != 0);
-   bClrDepth = ((mask & DD_DEPTH_BIT) != 0) && (ctx->Visual.depthBits != 0);
-   bClrStencil = ((mask & DD_STENCIL_BIT) != 0) && (ctx->Visual.stencilBits != 0);
+   bClrColor = (mask & (BUFFER_BIT_BACK_LEFT | BUFFER_BIT_FRONT_LEFT)) != 0;
+   bClrDepth = (mask & BUFFER_BIT_DEPTH) != 0;
+   bClrStencil = (mask & BUFFER_BIT_STENCIL) != 0;
 
    if (smesa->GlobalFlag & GFLAG_RENDER_STATES)
       sis_update_render_state( smesa );
 
-   if (!bClrColor)
-      dwEnable2 |= MASK_ColorMaskWriteEnable;
-
    if (bClrStencil) {
       dwSten1 = STENCIL_FORMAT_8 | SiS_STENCIL_ALWAYS |
-         (ctx->Stencil.Clear << 8) | 0xff;
+         ((ctx->Stencil.Clear & 0xff) << 8) | 0xff;
       dwSten2 = SiS_SFAIL_REPLACE | SiS_SPASS_ZFAIL_REPLACE |
          SiS_SPASS_ZPASS_REPLACE;
-      dwEnable1 = MASK_ZWriteEnable | MASK_StencilTestEnable;
+      dwEnable1 = MASK_ZWriteEnable | MASK_StencilWriteEnable |
+       MASK_StencilTestEnable;
       dwEnable2 |= MASK_ZMaskWriteEnable;
-      dwDepthMask |= ctx->Stencil.WriteMask[0] << 24;
+      dwDepthMask |= (ctx->Stencil.WriteMask[0] & 0xff) << 24;
    } else if (bClrDepth) {
       dwEnable1 = MASK_ZWriteEnable;
       dwEnable2 |= MASK_ZMaskWriteEnable;
@@ -254,7 +243,7 @@ sis_3D_Clear( GLcontext * ctx, GLbitfield mask,
       dirtyflags |= GFLAG_STENCILSETTING;
    }
 
-   if (mask & DD_FRONT_LEFT_BIT) {
+   if (mask & BUFFER_BIT_FRONT_LEFT) {
       pExtents = smesa->driDrawable->pClipRects;
       count = smesa->driDrawable->numClipRects;
    } else {
@@ -319,36 +308,18 @@ sis_3D_Clear( GLcontext * ctx, GLbitfield mask,
       MMIO(REG_3D_TSXb, *(GLint *) &right);
       MMIO(REG_3D_TSYb, *(GLint *) &bottom);
       MMIO(REG_3D_TSARGBb, smesa->clearColorPattern);
-    }
+   }
 
    mEndPrimitive();
 
-   smesa->GlobalFlag |= dirtyflags;
-
-   return (mask & ~(DD_BACK_LEFT_BIT | DD_DEPTH_BIT | DD_STENCIL_BIT));
-}
-#endif
-
-static void
-sis_bitblt_clear_cmd( sisContextPtr smesa, ENGPACKET * pkt )
-{
-   GLint *lpdwDest, *lpdwSrc;
-   int i;
-
-   lpdwSrc = (GLint *) pkt + 1;
-   lpdwDest = (GLint *) (GET_IOBase (smesa) + REG_SRC_ADDR) + 1;
+   /* If BUFFER_BIT_FRONT_LEFT is set, we've only cleared the front buffer so far */
+   if ((mask & BUFFER_BIT_FRONT_LEFT) != 0 && (mask & BUFFER_BIT_BACK_LEFT) != 0)
+      sis_3D_Clear( ctx, BUFFER_BIT_BACK_LEFT, x, y, width, height );
 
-   mWait3DCmdQueue (10);
-
-   *lpdwDest++ = *lpdwSrc++;
-   lpdwSrc++;
-   lpdwDest++;
-   for (i = 3; i < 8; i++) {
-      *lpdwDest++ = *lpdwSrc++;
-   }
+   smesa->GlobalFlag |= dirtyflags;
 
-   MMIO(REG_CMD0, *(GLint *) & pkt->stdwCmd);
-   MMIO(REG_QueueLen, -1);
+   return mask & ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL | BUFFER_BIT_BACK_LEFT |
+      BUFFER_BIT_FRONT_LEFT);
 }
 
 static void
@@ -356,27 +327,26 @@ sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x, GLint y,
                        GLint width, GLint height )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
-
    int count;
-   GLuint depth = GET_DEPTH (smesa);
-   XF86DRIClipRectPtr pExtents = NULL;
+   drm_clip_rect_t *pExtents = NULL;
    GLint xx, yy;
    GLint x0, y0, width0, height0;
 
-   ENGPACKET stEngPacket;
-
    /* Clear back buffer */
-   if (mask & DD_BACK_LEFT_BIT) {
-      smesa->cbClearPacket.stdwDestPos.wY = y;
-      smesa->cbClearPacket.stdwDestPos.wX = x;
-      smesa->cbClearPacket.stdwDim.wWidth = (GLshort) width;
-      smesa->cbClearPacket.stdwDim.wHeight = (GLshort) height;
-      smesa->cbClearPacket.dwFgRopColor = smesa->clearColorPattern;
-
-      sis_bitblt_clear_cmd( smesa, &smesa->cbClearPacket );
+   if (mask & BUFFER_BIT_BACK_LEFT) {
+      mWait3DCmdQueue (8);
+      MMIO(REG_SRC_PITCH, (smesa->bytesPerPixel == 4) ? 
+                          BLIT_DEPTH_32 : BLIT_DEPTH_16);
+      MMIO(REG_DST_X_Y, (x << 16) | y);
+      MMIO(REG_DST_ADDR, smesa->back.offset);
+      MMIO(REG_DST_PITCH_HEIGHT, (smesa->virtualY << 16) | smesa->back.pitch);
+      MMIO(REG_WIDTH_HEIGHT, (height << 16) | width);
+      MMIO(REG_PATFG, smesa->clearColorPattern);
+      MMIO(REG_BLIT_CMD, CMD_DIR_X_INC | CMD_DIR_Y_INC | CMD_ROP_PAT);
+      MMIO(REG_CommandQueue, -1);
    }
   
-   if ((mask & DD_FRONT_LEFT_BIT) == 0)
+   if ((mask & BUFFER_BIT_FRONT_LEFT) == 0)
       return;
 
    /* Clear front buffer */
@@ -388,23 +358,6 @@ sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x, GLint y,
    pExtents = smesa->driDrawable->pClipRects;
    count = smesa->driDrawable->numClipRects;
 
-   memset( &stEngPacket, 0, sizeof (ENGPACKET) );
-
-   stEngPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xc0000000;
-   stEngPacket.dwDestBaseAddr = smesa->frontOffset;
-   stEngPacket.wDestPitch = smesa->frontPitch;
-   /* TODO: set maximum value? */
-   stEngPacket.wDestHeight = smesa->virtualY;
-   stEngPacket.stdwCmd.cRop = 0xf0;
-   stEngPacket.dwFgRopColor = smesa->clearColorPattern;
-
-   /* for SGRAM Block Write Enable */
-   if (smesa->blockWrite)
-      stEngPacket.stdwCmd.cCmd0 = CMD0_PAT_FG_COLOR;
-   else
-      stEngPacket.stdwCmd.cCmd0 = 0;
-   stEngPacket.stdwCmd.cCmd1 = CMD1_DIR_X_INC | CMD1_DIR_Y_INC;
-
    while (count--) {
       GLint x2 = pExtents->x1 - smesa->driDrawable->x;
       GLint y2 = pExtents->y1 - smesa->driDrawable->y;
@@ -422,12 +375,16 @@ sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x, GLint y,
       if (width <= 0 || height <= 0)
        continue;
 
-      stEngPacket.stdwDestPos.wY = y;
-      stEngPacket.stdwDestPos.wX = x;
-      stEngPacket.stdwDim.wWidth = (GLshort)width;
-      stEngPacket.stdwDim.wHeight = (GLshort)height;
-
-      sis_bitblt_clear_cmd( smesa, &stEngPacket );
+      mWait3DCmdQueue (8);
+      MMIO(REG_SRC_PITCH, (smesa->bytesPerPixel == 4) ? 
+                          BLIT_DEPTH_32 : BLIT_DEPTH_16);
+      MMIO(REG_DST_X_Y, (x << 16) | y);
+      MMIO(REG_DST_ADDR, smesa->front.offset);
+      MMIO(REG_DST_PITCH_HEIGHT, (smesa->virtualY << 16) | smesa->front.pitch);
+      MMIO(REG_WIDTH_HEIGHT, (height << 16) | width);
+      MMIO(REG_PATFG, smesa->clearColorPattern);
+      MMIO(REG_BLIT_CMD, CMD_DIR_X_INC | CMD_DIR_Y_INC | CMD_ROP_PAT);
+      MMIO(REG_CommandQueue, -1);
    }
 }
 
@@ -436,19 +393,17 @@ sis_clear_z_stencil_buffer( GLcontext * ctx, GLbitfield mask,
                            GLint x, GLint y, GLint width, GLint height )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
-
-   /* TODO: check write mask */
-
-   if ( smesa->depthbuffer == NULL )
-      return;
-
-   /* TODO: consider alignment of width, height? */
-   smesa->zClearPacket.stdwDestPos.wY = y;
-   smesa->zClearPacket.stdwDestPos.wX = x;
-   smesa->zClearPacket.stdwDim.wWidth = (GLshort) width;
-   smesa->zClearPacket.stdwDim.wHeight = (GLshort) height;
-   smesa->zClearPacket.dwFgRopColor = smesa->clearZStencilPattern;
-
-   sis_bitblt_clear_cmd( smesa, &smesa->zClearPacket );
+   int cmd;
+
+   mWait3DCmdQueue (8);
+   MMIO(REG_SRC_PITCH, (smesa->zFormat == SiS_ZFORMAT_Z16) ?
+                       BLIT_DEPTH_16 : BLIT_DEPTH_32);
+   MMIO(REG_DST_X_Y, (x << 16) | y);
+   MMIO(REG_DST_ADDR, smesa->depth.offset);
+   MMIO(REG_DST_PITCH_HEIGHT, (smesa->virtualY << 16) | smesa->depth.pitch);
+   MMIO(REG_WIDTH_HEIGHT, (height << 16) | width);
+   MMIO(REG_PATFG, smesa->clearZStencilPattern);
+   MMIO(REG_BLIT_CMD, CMD_DIR_X_INC | CMD_DIR_Y_INC | CMD_ROP_PAT);
+   MMIO(REG_CommandQueue, -1);
 }