Merge remote branch 'origin/7.8'
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_state.c
index 0d1728b747a38a50aeb022aea725e057d8bbe9ab..539b067742fda0b588a0b13fe98af4d343547f55 100644 (file)
@@ -37,14 +37,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/api_arrayelt.h"
 #include "main/enums.h"
 #include "main/light.h"
-#include "main/state.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
+#include "main/simple_list.h"
 
 #include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
+#include "drivers/common/meta.h"
 
 #include "radeon_context.h"
 #include "radeon_mipmap_tree.h"
@@ -53,7 +54,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "radeon_tcl.h"
 #include "radeon_tex.h"
 #include "radeon_swtcl.h"
-#include "drirenderbuffer.h"
 
 static void radeonUpdateSpecular( GLcontext *ctx );
 
@@ -520,10 +520,10 @@ static void radeonColorMask( GLcontext *ctx,
      return;
 
    mask = radeonPackColor( rrb->cpp,
-                          ctx->Color.ColorMask[RCOMP],
-                          ctx->Color.ColorMask[GCOMP],
-                          ctx->Color.ColorMask[BCOMP],
-                          ctx->Color.ColorMask[ACOMP] );
+                          ctx->Color.ColorMask[0][RCOMP],
+                          ctx->Color.ColorMask[0][GCOMP],
+                          ctx->Color.ColorMask[0][BCOMP],
+                          ctx->Color.ColorMask[0][ACOMP] );
 
    if ( rmesa->hw.msk.cmd[MSK_RB3D_PLANEMASK] != mask ) {
       RADEON_STATECHANGE( rmesa, msk );
@@ -549,7 +549,7 @@ static void radeonPolygonOffset( GLcontext *ctx,
    rmesa->hw.zbs.cmd[ZBS_SE_ZBIAS_CONSTANT] = constant.ui32;
 }
 
-static void radeonPolygonStipple( GLcontext *ctx, const GLubyte *mask )
+static void radeonPolygonStipplePreKMS( GLcontext *ctx, const GLubyte *mask )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
    GLuint i;
@@ -570,7 +570,7 @@ static void radeonPolygonStipple( GLcontext *ctx, const GLubyte *mask )
     */
    stipple.mask = rmesa->state.stipple.mask;
    drmCommandWrite( rmesa->radeon.dri.fd, DRM_RADEON_STIPPLE,
-                    &stipple, sizeof(drm_radeon_stipple_t) );
+                   &stipple, sizeof(drm_radeon_stipple_t) );
    UNLOCK_HARDWARE( &rmesa->radeon );
 }
 
@@ -838,7 +838,7 @@ void radeonUpdateMaterial( GLcontext *ctx )
    if (ctx->Light.ColorMaterialEnabled)
       mask &= ~ctx->Light.ColorMaterialBitmask;
 
-   if (RADEON_DEBUG & DEBUG_STATE)
+   if (RADEON_DEBUG & RADEON_STATE)
       fprintf(stderr, "%s\n", __FUNCTION__);
 
 
@@ -1399,7 +1399,7 @@ static void radeonClearStencil( GLcontext *ctx, GLint s )
 void radeonUpdateWindow( GLcontext *ctx )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
-   __DRIdrawablePrivate *dPriv = radeon_get_drawable(&rmesa->radeon);
+   __DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
    GLfloat xoffset = dPriv ? (GLfloat) dPriv->x : 0;
    GLfloat yoffset = dPriv ? (GLfloat) dPriv->y + dPriv->h : 0;
    const GLfloat *v = ctx->Viewport._WindowMap.m;
@@ -1454,7 +1454,7 @@ static void radeonDepthRange( GLcontext *ctx, GLclampd nearval,
 void radeonUpdateViewportOffset( GLcontext *ctx )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
-   __DRIdrawablePrivate *dPriv = radeon_get_drawable(&rmesa->radeon);
+   __DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
    GLfloat xoffset = (GLfloat)dPriv->x;
    GLfloat yoffset = (GLfloat)dPriv->y + dPriv->h;
    const GLfloat *v = ctx->Viewport._WindowMap.m;
@@ -1572,7 +1572,7 @@ static void radeonEnable( GLcontext *ctx, GLenum cap, GLboolean state )
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
    GLuint p, flag;
 
-   if ( RADEON_DEBUG & DEBUG_STATE )
+   if ( RADEON_DEBUG & RADEON_STATE )
       fprintf( stderr, "%s( %s = %s )\n", __FUNCTION__,
               _mesa_lookup_enum_by_nr( cap ),
               state ? "GL_TRUE" : "GL_FALSE" );
@@ -1866,7 +1866,7 @@ static void radeonLightingSpaceChange( GLcontext *ctx )
    GLboolean tmp;
    RADEON_STATECHANGE( rmesa, tcl );
 
-   if (RADEON_DEBUG & DEBUG_STATE)
+   if (RADEON_DEBUG & RADEON_STATE)
       fprintf(stderr, "%s %d BEFORE %x\n", __FUNCTION__, ctx->_NeedEyeCoords,
              rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]);
 
@@ -1881,7 +1881,7 @@ static void radeonLightingSpaceChange( GLcontext *ctx )
       rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= ~RADEON_RESCALE_NORMALS;
    }
 
-   if (RADEON_DEBUG & DEBUG_STATE)
+   if (RADEON_DEBUG & RADEON_STATE)
       fprintf(stderr, "%s %d AFTER %x\n", __FUNCTION__, ctx->_NeedEyeCoords,
              rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]);
 }
@@ -1901,7 +1901,7 @@ void radeonUploadTexMatrix( r100ContextPtr rmesa,
    So: if we need the q coord in the end (solely determined by the texture
    target, i.e. 2d / 1d / texrect targets) we swap the third and 4th row.
    Additionally, if we don't have texgen but 4 tex coords submitted, we swap
-   column 3 and 4 (for the 2d / 1d / texrect targets) since the the q coord
+   column 3 and 4 (for the 2d / 1d / texrect targets) since the q coord
    will get submitted in the "wrong", i.e. 3rd, slot.
    If an app submits 3 coords for 2d targets, we assume it is saving on vertex
    size and using the texture matrix to swap the r and q coords around (ut2k3
@@ -2099,7 +2099,7 @@ static GLboolean r100ValidateBuffers(GLcontext *ctx)
                           RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0);
    }
 
-   ret = radeon_cs_space_check_with_bo(rmesa->radeon.cmdbuf.cs, rmesa->radeon.dma.current, RADEON_GEM_DOMAIN_GTT, 0);
+   ret = radeon_cs_space_check_with_bo(rmesa->radeon.cmdbuf.cs, first_elem(&rmesa->radeon.dma.reserved)->bo, RADEON_GEM_DOMAIN_GTT, 0);
    if (ret)
        return GL_FALSE;
    return GL_TRUE;
@@ -2221,25 +2221,44 @@ static void radeonWrapRunPipeline( GLcontext *ctx )
    }
 }
 
+static void radeonPolygonStipple( GLcontext *ctx, const GLubyte *mask )
+{
+   r100ContextPtr r100 = R100_CONTEXT(ctx);
+   GLint i;
+
+   radeon_firevertices(&r100->radeon);
+
+   RADEON_STATECHANGE(r100, stp);
+
+   /* Must flip pattern upside down.
+    */
+   for ( i = 31 ; i >= 0; i--) {
+     r100->hw.stp.cmd[3 + i] = ((GLuint *) mask)[i];
+   }
+}
+
 
 /* Initialize the driver's state functions.
  * Many of the ctx->Driver functions might have been initialized to
  * software defaults in the earlier _mesa_init_driver_functions() call.
  */
-void radeonInitStateFuncs( GLcontext *ctx )
+void radeonInitStateFuncs( GLcontext *ctx , GLboolean dri2 )
 {
    ctx->Driver.UpdateState             = radeonInvalidateState;
    ctx->Driver.LightingSpaceChange      = radeonLightingSpaceChange;
 
    ctx->Driver.DrawBuffer              = radeonDrawBuffer;
    ctx->Driver.ReadBuffer              = radeonReadBuffer;
+   ctx->Driver.CopyPixels               = _mesa_meta_CopyPixels;
+   ctx->Driver.DrawPixels               = _mesa_meta_DrawPixels;
+   if (dri2)
+          ctx->Driver.ReadPixels               = radeonReadPixels;
 
    ctx->Driver.AlphaFunc               = radeonAlphaFunc;
    ctx->Driver.BlendEquationSeparate   = radeonBlendEquationSeparate;
    ctx->Driver.BlendFuncSeparate       = radeonBlendFuncSeparate;
    ctx->Driver.ClearColor              = radeonClearColor;
    ctx->Driver.ClearDepth              = radeonClearDepth;
-   ctx->Driver.ClearIndex              = NULL;
    ctx->Driver.ClearStencil            = radeonClearStencil;
    ctx->Driver.ClipPlane               = radeonClipPlane;
    ctx->Driver.ColorMask               = radeonColorMask;
@@ -2251,7 +2270,6 @@ void radeonInitStateFuncs( GLcontext *ctx )
    ctx->Driver.Fogfv                   = radeonFogfv;
    ctx->Driver.FrontFace               = radeonFrontFace;
    ctx->Driver.Hint                    = NULL;
-   ctx->Driver.IndexMask               = NULL;
    ctx->Driver.LightModelfv            = radeonLightModelfv;
    ctx->Driver.Lightfv                 = radeonLightfv;
    ctx->Driver.LineStipple              = radeonLineStipple;
@@ -2259,7 +2277,10 @@ void radeonInitStateFuncs( GLcontext *ctx )
    ctx->Driver.LogicOpcode             = radeonLogicOpCode;
    ctx->Driver.PolygonMode             = radeonPolygonMode;
    ctx->Driver.PolygonOffset           = radeonPolygonOffset;
-   ctx->Driver.PolygonStipple          = radeonPolygonStipple;
+   if (dri2)
+      ctx->Driver.PolygonStipple               = radeonPolygonStipple;
+   else
+      ctx->Driver.PolygonStipple               = radeonPolygonStipplePreKMS;
    ctx->Driver.RenderMode              = radeonRenderMode;
    ctx->Driver.Scissor                 = radeonScissor;
    ctx->Driver.ShadeModel              = radeonShadeModel;