r300: add full support for two sided stencil on r5xx for dri2
authorAlex Deucher <alexdeucher@gmail.com>
Thu, 10 Sep 2009 16:01:19 +0000 (12:01 -0400)
committerAlex Deucher <alexdeucher@gmail.com>
Thu, 10 Sep 2009 16:01:19 +0000 (12:01 -0400)
src/mesa/drivers/dri/r300/r300_cmdbuf.c
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_reg.h
src/mesa/drivers/dri/r300/r300_state.c

index 0fe32a5443aeeb3885e6d6da9419979cf4f4bfaa..dd1a0fe8132cc36a88b2e900649ace766337c48d 100644 (file)
@@ -697,6 +697,14 @@ void r300InitCmdBuf(r300ContextPtr r300)
        ALLOC_STATE(zs, always, R300_ZS_CMDSIZE, 0);
        r300->hw.zs.cmd[R300_ZS_CMD_0] =
            cmdpacket0(r300->radeon.radeonScreen, R300_ZB_CNTL, 3);
+       if (is_r500) {
+               if (r300->radeon.radeonScreen->kernel_mm)
+                       ALLOC_STATE(zsb, always, R300_ZSB_CMDSIZE, 0);
+               else
+                       ALLOC_STATE(zsb, never, R300_ZSB_CMDSIZE, 0);
+               r300->hw.zsb.cmd[R300_ZSB_CMD_0] =
+                       cmdpacket0(r300->radeon.radeonScreen, R500_ZB_STENCILREFMASK_BF, 1);
+       }
 
        ALLOC_STATE(zstencil_format, always, 5, 0);
        r300->hw.zstencil_format.cmd[0] =
index 1dadcc0a69783ba92dd610868457fe0fc49a6252..518d5cdbf4f5908a93ecc61091d9e81e411f70a0 100644 (file)
@@ -234,6 +234,10 @@ typedef struct r300_context *r300ContextPtr;
 #define R300_ZS_CNTL_2         3
 #define R300_ZS_CMDSIZE                4
 
+#define R300_ZSB_CMD_0         0
+#define R300_ZSB_CNTL_0                1
+#define R300_ZSB_CMDSIZE       2
+
 #define R300_ZB_CMD_0          0
 #define R300_ZB_OFFSET         1
 #define R300_ZB_PITCH          2
@@ -343,6 +347,7 @@ struct r300_hw_state {
        struct radeon_state_atom rb3d_aaresolve_ctl;    /* (4E88) */
        struct radeon_state_atom rb3d_discard_src_pixel_lte_threshold;  /* (4E88) I saw it only written on RV350 hardware..  */
        struct radeon_state_atom zs;    /* zstencil control (4F00) */
+       struct radeon_state_atom zsb;   /* zstencil bf */
        struct radeon_state_atom zstencil_format;
        struct radeon_state_atom zb;    /* z buffer (4F20) */
        struct radeon_state_atom zb_depthclearvalue;    /* (4F28) */
index 98512d778e351c4ef0db5e1f9ed15498cc7a2b54..b9ccd098dc8eea83d3a48c3df7809540eb1b20c0 100644 (file)
@@ -2313,6 +2313,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #      define R300_Z_WRITE_ENABLE               (1 << 2)
 #      define R300_Z_SIGNED_COMPARE             (1 << 3)
 #      define R300_STENCIL_FRONT_BACK           (1 << 4)
+#      define R400_ZSIGNED_MAGNITUDE            (1 << 5)
+#      define R500_STENCIL_REFMASK_FRONT_BACK   (1 << 6)
 
 #define R300_ZB_ZSTENCILCNTL                   0x4f04
        /* functions */
index d4c3ecee6697f50a063491d61a25f82bb498eef4..3060f49aaf8ac27376255137bd4300cc80d2be71 100644 (file)
@@ -590,7 +590,9 @@ static void r300SetDepthState(GLcontext * ctx)
        r300ContextPtr r300 = R300_CONTEXT(ctx);
 
        R300_STATECHANGE(r300, zs);
-       r300->hw.zs.cmd[R300_ZS_CNTL_0] &= R300_STENCIL_ENABLE|R300_STENCIL_FRONT_BACK;
+       r300->hw.zs.cmd[R300_ZS_CNTL_0] &= (R300_STENCIL_ENABLE |
+                                           R300_STENCIL_FRONT_BACK |
+                                           R500_STENCIL_REFMASK_FRONT_BACK);
        r300->hw.zs.cmd[R300_ZS_CNTL_1] &= ~(R300_ZS_MASK << R300_Z_FUNC_SHIFT);
 
        if (ctx->Depth.Test) {
@@ -604,11 +606,16 @@ static void r300SetDepthState(GLcontext * ctx)
 
 static void r300CatchStencilFallback(GLcontext *ctx)
 {
+       r300ContextPtr rmesa = R300_CONTEXT(ctx);
        const unsigned back = ctx->Stencil._BackFace;
 
-       if (ctx->Stencil._Enabled && (ctx->Stencil.Ref[0] != ctx->Stencil.Ref[back]
-               || ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[back]
-               || ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[back])) {
+       if (rmesa->radeon.radeonScreen->kernel_mm &&
+           (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515)) {
+               r300SwitchFallback(ctx, R300_FALLBACK_STENCIL_TWOSIDE, GL_FALSE);
+       } else if (ctx->Stencil._Enabled &&
+                  (ctx->Stencil.Ref[0] != ctx->Stencil.Ref[back]
+                   || ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[back]
+                   || ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[back])) {
                r300SwitchFallback(ctx, R300_FALLBACK_STENCIL_TWOSIDE, GL_TRUE);
        } else {
                r300SwitchFallback(ctx, R300_FALLBACK_STENCIL_TWOSIDE, GL_FALSE);
@@ -915,11 +922,24 @@ static void r300StencilFuncSeparate(GLcontext * ctx, GLenum face,
        rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |=
            (flag << R300_S_BACK_FUNC_SHIFT);
        rmesa->hw.zs.cmd[R300_ZS_CNTL_2] |= refmask;
+
+       if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
+               rmesa->hw.zs.cmd[R300_ZS_CNTL_0] |= R500_STENCIL_REFMASK_FRONT_BACK;
+               R300_STATECHANGE(rmesa, zsb);
+               refmask = ((ctx->Stencil.Ref[back] & 0xff) << R300_STENCILREF_SHIFT)
+                       | ((ctx->Stencil.ValueMask[back] & 0xff) << R300_STENCILMASK_SHIFT);
+
+               rmesa->hw.zsb.cmd[R300_ZSB_CNTL_0] &=
+                       ~((R300_STENCILREF_MASK << R300_STENCILREF_SHIFT) |
+                         (R300_STENCILREF_MASK << R300_STENCILMASK_SHIFT));
+               rmesa->hw.zsb.cmd[R300_ZSB_CNTL_0] |= refmask;
+       }
 }
 
 static void r300StencilMaskSeparate(GLcontext * ctx, GLenum face, GLuint mask)
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       const unsigned back = ctx->Stencil._BackFace;
 
        r300CatchStencilFallback(ctx);
 
@@ -931,6 +951,13 @@ static void r300StencilMaskSeparate(GLcontext * ctx, GLenum face, GLuint mask)
            (ctx->Stencil.
             WriteMask[0] & R300_STENCILREF_MASK) <<
             R300_STENCILWRITEMASK_SHIFT;
+       if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
+               R300_STATECHANGE(rmesa, zsb);
+               rmesa->hw.zsb.cmd[R300_ZSB_CNTL_0] |=
+                       (ctx->Stencil.
+                        WriteMask[back] & R300_STENCILREF_MASK) <<
+                       R300_STENCILWRITEMASK_SHIFT;
+       }
 }
 
 static void r300StencilOpSeparate(GLcontext * ctx, GLenum face,