Removing some regs that are wrong and adding some comments to r300_reg.h .
[mesa.git] / src / mesa / drivers / dri / r300 / r300_state.c
index f8d3de65d31f40e89016c8619982b0717f2bb2bc..bbbf674ee1a6142cd88dde0dfbcfdd0d4d103681 100644 (file)
@@ -502,16 +502,25 @@ static void r300Enable(GLcontext* ctx, GLenum cap, GLboolean state)
        case GL_POLYGON_OFFSET_POINT:
        case GL_POLYGON_OFFSET_LINE:
                WARN_ONCE("Don't know how to enable polygon offset point/line. Help me !\n");
+               
+               /* Something is apparently blocking these from working */
+               R300_STATECHANGE(r300, unk42B4);
+               if(state){
+                       r300->hw.unk42B4.cmd[1] |= ~(3<<0);
+               } else {
+                       r300->hw.unk42B4.cmd[1] &= (3<<0);
+               }
                break;
                
        case GL_POLYGON_OFFSET_FILL:
                R300_STATECHANGE(r300, unk42B4);
                if(state){
-                       r300->hw.unk42B4.cmd[1] |= 3;
-                       } else {
-                       r300->hw.unk42B4.cmd[1] &= ~3;
-                       }
+                       r300->hw.unk42B4.cmd[1] |= (3<<0);
+               } else {
+                       r300->hw.unk42B4.cmd[1] &= ~(3<<0);
+               }
                break;
+               
        case GL_VERTEX_PROGRAM_ARB:
                //TCL_FALLBACK(rmesa->glCtx, R200_TCL_FALLBACK_TCL_DISABLE, state);
        break;
@@ -631,11 +640,126 @@ static void r300ColorMask(GLcontext* ctx,
 static void r300PointSize(GLcontext * ctx, GLfloat size)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-
+       
+       /* TODO: Validate point size */
+       R300_STATECHANGE(r300, ps);
+       r300->hw.ps.cmd[R300_PS_POINTSIZE] =
+               ((int)(size * 6) << R300_POINTSIZE_X_SHIFT) |
+               ((int)(size * 6) << R300_POINTSIZE_Y_SHIFT);
+       
+#if 0 /* r200 reg? */
        /* This might need fixing later */
        R300_STATECHANGE(r300, vps);
        r300->hw.vps.cmd[R300_VPS_POINTSIZE] = r300PackFloat32(1.0);
+#endif 
+}
+
+/* =============================================================
+ * Line state
+ */
+static void r300LineWidth(GLcontext *ctx, GLfloat widthf)
+{
+       r300ContextPtr r300 = R300_CONTEXT(ctx);
+       /* IMHO mesa isnt clamping line widths according to ctx->Const.*LineWidth
+          before calling this from the dd function table.
+          Since r300ResetHwState calls these with clamped values,
+          they must be set properly. */
+       
+       R300_STATECHANGE(r300, lcntl);
+       r300->hw.lcntl.cmd[1] = (int)(widthf * 6.0);
+       /* Doesnt look very good without this... */
+       r300->hw.lcntl.cmd[1] |= R300_LINE_CNT_UNK1;
+}
+
+/*
+
+glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); :  00000091 (  1001 0001)
+glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); : 00000001 (          1)
+
+glPolygonMode(GL_FRONT, GL_LINE); :           00000111 (1 0001 0001)
+glPolygonMode(GL_FRONT, GL_POINT); :          00000101 (1 0000 0001)
+
+glPolygonMode(GL_BACK, GL_LINE); :            000000a1 (  1010 0001)
+glPolygonMode(GL_BACK, GL_POINT); :           00000021 (    10 0001)
+
+*/
+
+/* exclusive */
+#define PM_NOT_BACK   (1<<8)
+#define PM_NOT_FRONT  (1<<5)
+
+#define PM_FRONT_LINE (1<<4)
+#define PM_BACK_LINE  (1<<7)
+
+static void r300PolygonMode(GLcontext *ctx, GLenum face, GLenum mode)
+{
+       r300ContextPtr r300 = R300_CONTEXT(ctx);
+       unsigned long hw_mode=0;
+       
+       hw_mode=r300->hw.unk4288.cmd[1];
+       hw_mode |= 1; /* enables point mode by default */
+
+       switch (face) {
+       case GL_FRONT:
+               //fprintf(stderr, "front\n");
+               hw_mode &= ~PM_NOT_FRONT;
+               switch (mode) {
+               case GL_LINE:
+                       hw_mode |= PM_FRONT_LINE;
+               break;
+               case GL_POINT:
+                       hw_mode &= ~PM_FRONT_LINE;
+               break;
+               case GL_FILL: /* No idea */
+                       hw_mode = 0;
+               break;
+               }
+       break;
+       
+       case GL_BACK:
+               //fprintf(stderr, "back\n");
+               hw_mode &= ~PM_NOT_BACK;
+               switch (mode) {
+               case GL_LINE:
+                       hw_mode |= PM_BACK_LINE;
+               break;
+               case GL_POINT:
+                       hw_mode &= ~PM_BACK_LINE;
+               break;
+               case GL_FILL: /* No idea */
+                       hw_mode = 0;
+               break;
+               }
+       break;
+       
+       case GL_FRONT_AND_BACK:
+               //fprintf(stderr, "front and back\n");
+               hw_mode &= ~PM_NOT_FRONT;
+               hw_mode &= ~PM_NOT_BACK;
+               switch (mode) {
+               case GL_LINE:
+                       hw_mode |= PM_FRONT_LINE;
+                       hw_mode |= PM_BACK_LINE;
+               break;
+               case GL_POINT:
+                       hw_mode &= ~PM_FRONT_LINE;
+                       hw_mode &= ~PM_BACK_LINE;
+               break;
+               case GL_FILL:
+                       hw_mode = 0;
+               break;
+               }
+       break;
+       }
+       
+       //if( front and back fill) hw_mode=0;
+       
+       if(r300->hw.unk4288.cmd[1] != hw_mode){
+               R300_STATECHANGE(r300, unk4288);
+               r300->hw.unk4288.cmd[1] = hw_mode;
+       }
 }
+
 /* =============================================================
  * Stencil
  */
@@ -705,7 +829,7 @@ static void r300StencilFunc(GLcontext * ctx, GLenum func,
                           ValueMask[0] << R300_RB3D_ZS2_STENCIL_MASK_SHIFT));
        GLuint flag;
 
-       R200_STATECHANGE(rmesa, zs);
+       R300_STATECHANGE(rmesa, zs);
 
        rmesa->hw.zs.cmd[R300_ZS_CNTL_1] &= ~(
                (R300_ZS_MASK << R300_RB3D_ZS1_FRONT_FUNC_SHIFT)
@@ -724,7 +848,7 @@ static void r300StencilMask(GLcontext * ctx, GLuint mask)
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
 
-       R200_STATECHANGE(rmesa, zs);
+       R300_STATECHANGE(rmesa, zs);
        rmesa->hw.zs.cmd[R300_ZS_CNTL_2]  &= ~(R300_ZS_MASK << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT);
        rmesa->hw.zs.cmd[R300_ZS_CNTL_2] |= ctx->Stencil.WriteMask[0] << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT;
 }
@@ -735,7 +859,7 @@ static void r300StencilOp(GLcontext * ctx, GLenum fail,
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
 
-       R200_STATECHANGE(rmesa, zs);
+       R300_STATECHANGE(rmesa, zs);
                /* It is easier to mask what's left.. */
        rmesa->hw.zs.cmd[R300_ZS_CNTL_1] &= (R300_ZS_MASK << R300_RB3D_ZS1_DEPTH_FUNC_SHIFT);
 
@@ -754,7 +878,7 @@ static void r300ClearStencil(GLcontext * ctx, GLint s)
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
 
        /* Not sure whether this is correct.. */
-       R200_STATECHANGE(rmesa, zs);
+       R300_STATECHANGE(rmesa, zs);
        rmesa->hw.zs.cmd[R300_ZS_CNTL_2] =
            ((GLuint) ctx->Stencil.Clear |
             (0xff << R200_STENCIL_MASK_SHIFT) |
@@ -804,7 +928,7 @@ static void r300Viewport(GLcontext * ctx, GLint x, GLint y,
         * setting below.  Could apply deltas to rescue pipelined viewport
         * values, or keep the originals hanging around.
         */
-       R200_FIREVERTICES(R200_CONTEXT(ctx));
+       R300_FIREVERTICES(R300_CONTEXT(ctx));
        r300UpdateWindow(ctx);
 }
 
@@ -816,7 +940,6 @@ static void r300DepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
 /* =============================================================
  * Polygon state
  */
-
 static void r300PolygonOffset(GLcontext * ctx, GLfloat factor, GLfloat units)
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
@@ -833,7 +956,6 @@ static void r300PolygonOffset(GLcontext * ctx, GLfloat factor, GLfloat units)
        rmesa->hw.zbs.cmd[R300_ZBS_W_CONSTANT] = r300PackFloat32(constant);
 }
 
-
 /* Routing and texture-related */
 
 void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
@@ -932,8 +1054,8 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
        if(tnl->render_inputs & _TNL_BIT_COLOR1)
                CONFIGURE_AOS(VB->SecondaryColorPtr[0], 0, i_color[1], AOS_FORMAT_FLOAT_COLOR);
        
-       if(tnl->render_inputs & _TNL_BIT_FOG)
-               CONFIGURE_AOS(VB->FogCoordPtr, 0, i_fog, AOS_FORMAT_FLOAT);
+       /*if(tnl->render_inputs & _TNL_BIT_FOG) // Causes lock ups when immediate mode is on
+               CONFIGURE_AOS(VB->FogCoordPtr, 0, i_fog, AOS_FORMAT_FLOAT);*/
        
        for(i=0;i < ctx->Const.MaxTextureUnits;i++)
                if(tnl->render_inputs & (_TNL_BIT_TEX0<<i))
@@ -1180,8 +1302,7 @@ void r300_setup_textures(GLcontext *ctx)
        R300_STATECHANGE(r300, tex.format);
        R300_STATECHANGE(r300, tex.offset);
        R300_STATECHANGE(r300, tex.unknown4);
-       R300_STATECHANGE(r300, tex.unknown5);
-       //R300_STATECHANGE(r300, tex.border_color);
+       R300_STATECHANGE(r300, tex.border_color);
 
        r300->state.texture.tc_count=0;
 
@@ -1211,7 +1332,7 @@ void r300_setup_textures(GLcontext *ctx)
                                }
                        //fprintf(stderr, "t->format=%08x\n", t->format);
                        if((t->format & 0xffffff00)==0xffffff00){
-                               WARN_ONCE("unknown texture format encountered. Help me !\n");
+                               WARN_ONCE("unknown texture format (entry %x) encountered. Help me !\n", t->format & 0xff);
                                //fprintf(stderr, "t->format=%08x\n", t->format);
                                }
                        if (RADEON_DEBUG & DEBUG_STATE)
@@ -1227,8 +1348,7 @@ void r300_setup_textures(GLcontext *ctx)
                        //fprintf(stderr, "t->format=%08x\n", t->format);
                        r300->hw.tex.offset.cmd[R300_TEX_VALUE_0+i]=r300->radeon.radeonScreen->fbLocation+t->offset;
                        r300->hw.tex.unknown4.cmd[R300_TEX_VALUE_0+i]=0x0;
-                       r300->hw.tex.unknown5.cmd[R300_TEX_VALUE_0+i]=0x0;
-                       //r300->hw.tex.border_color.cmd[R300_TEX_VALUE_0+i]=t->pp_border_color;
+                       r300->hw.tex.border_color.cmd[R300_TEX_VALUE_0+i]=t->pp_border_color;
                        }
                }
        ((drm_r300_cmd_header_t*)r300->hw.tex.filter.cmd)->unchecked_state.count = max_texture_unit+1;
@@ -1237,8 +1357,7 @@ void r300_setup_textures(GLcontext *ctx)
        ((drm_r300_cmd_header_t*)r300->hw.tex.format.cmd)->unchecked_state.count = max_texture_unit+1;
        ((drm_r300_cmd_header_t*)r300->hw.tex.offset.cmd)->unchecked_state.count = max_texture_unit+1;
        ((drm_r300_cmd_header_t*)r300->hw.tex.unknown4.cmd)->unchecked_state.count = max_texture_unit+1;
-       ((drm_r300_cmd_header_t*)r300->hw.tex.unknown5.cmd)->unchecked_state.count = max_texture_unit+1;
-       //((drm_r300_cmd_header_t*)r300->hw.tex.border_color.cmd)->unchecked_state.count = max_texture_unit+1;
+       ((drm_r300_cmd_header_t*)r300->hw.tex.border_color.cmd)->unchecked_state.count = max_texture_unit+1;
 
        if (RADEON_DEBUG & DEBUG_STATE)
                fprintf(stderr, "TX_ENABLE: %08x  max_texture_unit=%d\n", r300->hw.txe.cmd[R300_TXE_ENABLE], max_texture_unit);
@@ -1634,6 +1753,7 @@ static void r300InvalidateState(GLcontext * ctx, GLuint new_state)
        r300ResetHwState(r300);
 }
 
+void update_zbias(GLcontext * ctx, int prim);
 
 /**
  * Completely recalculates hardware state based on the Mesa state.
@@ -1767,13 +1887,22 @@ void r300ResetHwState(r300ContextPtr r300)
 
        r300->hw.unk4214.cmd[1] = 0x00050005;
 
+       r300PointSize(ctx, ctx->Point._Size);
+#if 0  
        r300->hw.ps.cmd[R300_PS_POINTSIZE] = (6 << R300_POINTSIZE_X_SHIFT) |
                                             (6 << R300_POINTSIZE_Y_SHIFT);
-
+#endif 
+                       
        r300->hw.unk4230.cmd[1] = 0x01800000;
        r300->hw.unk4230.cmd[2] = 0x00020006;
        r300->hw.unk4230.cmd[3] = r300PackFloat32(1.0 / 192.0);
-
+       
+       r300LineWidth(ctx, ctx->Line._Width);
+       
+#ifdef EXP_C
+       static int foobar=0;
+       r300->hw.lsf.cmd[1] = foobar++; //0x3a088889;
+#endif
        r300->hw.unk4260.cmd[1] = 0;
        r300->hw.unk4260.cmd[2] = r300PackFloat32(0.0);
        r300->hw.unk4260.cmd[3] = r300PackFloat32(1.0);
@@ -1783,25 +1912,29 @@ void r300ResetHwState(r300ContextPtr r300)
        r300->hw.unk4274.cmd[3] = 0x00000000;
        r300->hw.unk4274.cmd[4] = 0x00000000;
 
+       r300PolygonMode(ctx, GL_FRONT, ctx->Polygon.FrontMode);
+       r300PolygonMode(ctx, GL_BACK, ctx->Polygon.BackMode);
+#if 0
        r300->hw.unk4288.cmd[1] = 0x00000000;
+#endif 
        r300->hw.unk4288.cmd[2] = 0x00000001;
        r300->hw.unk4288.cmd[3] = 0x00000000;
        r300->hw.unk4288.cmd[4] = 0x00000000;
        r300->hw.unk4288.cmd[5] = 0x00000000;
 
        r300->hw.unk42A0.cmd[1] = 0x00000000;
-       
-#if 0
+
+       update_zbias(ctx, GL_TRIANGLES);/* FIXME */
+#if 0  
        r300->hw.unk42B4.cmd[1] = 0x00000000;
-#endif
-               
+#endif 
        r300->hw.unk42C0.cmd[1] = 0x4B7FFFFF;
        r300->hw.unk42C0.cmd[2] = 0x00000000;
 
 
        r300->hw.unk43A4.cmd[1] = 0x0000001C;
        r300->hw.unk43A4.cmd[2] = 0x2DA49525;
-
+       
        r300->hw.unk43E8.cmd[1] = 0x00FFFFFF;
 
        #if 0
@@ -1992,7 +2125,8 @@ void r300InitStateFuncs(struct dd_function_table* functions)
        functions->Viewport = r300Viewport;
        functions->DepthRange = r300DepthRange;
        functions->PointSize = r300PointSize;
-       
+       functions->LineWidth = r300LineWidth;
        
        functions->PolygonOffset = r300PolygonOffset;
+       functions->PolygonMode = r300PolygonMode;
 }