[Mesa-dev] [PATCH 01/31] mesa: replace _mesa_update_stencil() with helper functions

Marek Olšák maraeo at gmail.com
Mon Jun 12 16:55:26 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

The idea is to remove the dependency on _mesa_update_state_locked,
so that st/mesa can skip it for stencil state updates, and then stop
setting _NEW_STENCIL in mesa/main if the driver is st/mesa.

The main motivation is to stop invoking _mesa_update_state_locked for
certain state groups.
---
 src/mesa/drivers/common/driverfuncs.c            |  2 +-
 src/mesa/drivers/dri/i915/i915_state.c           |  2 +-
 src/mesa/drivers/dri/i915/intel_pixel.c          |  3 +-
 src/mesa/drivers/dri/i915/intel_pixel_copy.c     |  3 +-
 src/mesa/drivers/dri/i965/brw_cc.c               |  6 ++--
 src/mesa/drivers/dri/i965/brw_context.c          |  8 ++++++
 src/mesa/drivers/dri/i965/brw_context.h          |  5 ++++
 src/mesa/drivers/dri/i965/brw_draw.c             |  2 +-
 src/mesa/drivers/dri/i965/brw_wm.c               |  2 +-
 src/mesa/drivers/dri/i965/gen7_misc_state.c      |  2 +-
 src/mesa/drivers/dri/i965/gen8_depth_state.c     |  6 ++--
 src/mesa/drivers/dri/i965/genX_state_upload.c    |  6 ++--
 src/mesa/drivers/dri/i965/intel_pixel.c          |  3 +-
 src/mesa/drivers/dri/i965/intel_pixel_copy.c     |  3 +-
 src/mesa/drivers/dri/nouveau/nv04_state_raster.c |  2 +-
 src/mesa/drivers/dri/nouveau/nv10_state_raster.c |  2 +-
 src/mesa/drivers/dri/radeon/radeon_common.c      |  1 -
 src/mesa/main/mtypes.h                           |  3 --
 src/mesa/main/state.c                            |  3 --
 src/mesa/main/stencil.c                          | 28 ------------------
 src/mesa/main/stencil.h                          | 36 ++++++++++++++++++++----
 src/mesa/state_tracker/st_atom_depth.c           |  2 +-
 src/mesa/swrast/s_context.c                      |  3 +-
 src/mesa/swrast/s_span.c                         |  5 ++--
 src/mesa/swrast/s_triangle.c                     |  3 +-
 src/mesa/swrast_setup/ss_triangle.c              |  3 +-
 26 files changed, 78 insertions(+), 66 deletions(-)

diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index db0a107..5008ae8 100644
--- a/src/mesa/drivers/common/driverfuncs.c
+++ b/src/mesa/drivers/common/driverfuncs.c
@@ -243,21 +243,21 @@ _mesa_init_driver_state(struct gl_context *ctx)
    ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
    ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
    ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
    ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
    ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
    ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
    ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
    ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
    ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
    ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.EnableFlags);
-   ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
+   ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled);
    ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
    ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
    ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
    ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
    ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
 
    ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
    {
       GLfloat mode = (GLfloat) ctx->Fog.Mode;
       ctx->Driver.Fogfv(ctx, GL_FOG_MODE, &mode);
diff --git a/src/mesa/drivers/dri/i915/i915_state.c b/src/mesa/drivers/dri/i915/i915_state.c
index 715db1f..232fc9d 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -120,21 +120,21 @@ i915_update_stencil(struct gl_context * ctx)
                 S5_STENCIL_PASS_Z_PASS_MASK,
                 (front_ref << S5_STENCIL_REF_SHIFT) |
                 (intel_translate_compare_func(front_func) << S5_STENCIL_TEST_FUNC_SHIFT) |
                 (intel_translate_stencil_op(front_fail) << S5_STENCIL_FAIL_SHIFT) |
                 (intel_translate_stencil_op(front_pass_z_fail) <<
                  S5_STENCIL_PASS_Z_FAIL_SHIFT) |
                 (intel_translate_stencil_op(front_pass_z_pass) <<
                  S5_STENCIL_PASS_Z_PASS_SHIFT));
 
    /* Set back state if different from front. */
-   if (ctx->Stencil._TestTwoSide) {
+   if (_mesa_stencil_is_two_sided(ctx)) {
       set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS,
                    BFO_STENCIL_REF_MASK |
                    BFO_STENCIL_TEST_MASK |
                    BFO_STENCIL_FAIL_MASK |
                    BFO_STENCIL_PASS_Z_FAIL_MASK |
                    BFO_STENCIL_PASS_Z_PASS_MASK,
                    BFO_STENCIL_TWO_SIDE |
                    (back_ref << BFO_STENCIL_REF_SHIFT) |
                    (intel_translate_compare_func(back_func) << BFO_STENCIL_TEST_SHIFT) |
                    (intel_translate_stencil_op(back_fail) << BFO_STENCIL_FAIL_SHIFT) |
diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c
index feb1a3f..b536c9b 100644
--- a/src/mesa/drivers/dri/i915/intel_pixel.c
+++ b/src/mesa/drivers/dri/i915/intel_pixel.c
@@ -21,20 +21,21 @@
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  * 
  **************************************************************************/
 
 #include "main/accum.h"
 #include "main/enums.h"
 #include "main/state.h"
+#include "main/stencil.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "swrast/swrast.h"
 
 #include "intel_context.h"
 #include "intel_pixel.h"
 #include "intel_regions.h"
 
 #define FILE_DEBUG_FLAG DEBUG_PIXEL
 
@@ -103,21 +104,21 @@ intel_check_blit_fragment_ops(struct gl_context * ctx, bool src_alpha_is_one)
    if (ctx->Fog.Enabled) {
       DBG("fallback due to fog\n");
       return false;
    }
 
    if (ctx->_ImageTransferState) {
       DBG("fallback due to image transfer\n");
       return false;
    }
 
-   if (ctx->Stencil._Enabled) {
+   if (_mesa_stencil_is_enabled(ctx)) {
       DBG("fallback due to image stencil\n");
       return false;
    }
 
    if (ctx->RenderMode != GL_RENDER) {
       DBG("fallback due to render mode\n");
       return false;
    }
 
    return true;
diff --git a/src/mesa/drivers/dri/i915/intel_pixel_copy.c b/src/mesa/drivers/dri/i915/intel_pixel_copy.c
index 213cdbd..e447511 100644
--- a/src/mesa/drivers/dri/i915/intel_pixel_copy.c
+++ b/src/mesa/drivers/dri/i915/intel_pixel_copy.c
@@ -21,20 +21,21 @@
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  * 
  **************************************************************************/
 
 #include "main/glheader.h"
 #include "main/image.h"
 #include "main/state.h"
+#include "main/stencil.h"
 #include "main/mtypes.h"
 #include "main/condrender.h"
 #include "main/fbobject.h"
 #include "drivers/common/meta.h"
 
 #include "intel_context.h"
 #include "intel_buffers.h"
 #include "intel_mipmap_tree.h"
 #include "intel_regions.h"
 #include "intel_pixel.h"
@@ -104,21 +105,21 @@ do_blit_copypixels(struct gl_context * ctx,
    if (ctx->_ImageTransferState) {
       perf_debug("glCopyPixels(): Unsupported image transfer state\n");
       return false;
    }
 
    if (ctx->Depth.Test) {
       perf_debug("glCopyPixels(): Unsupported depth test state\n");
       return false;
    }
 
-   if (ctx->Stencil._Enabled) {
+   if (_mesa_stencil_is_enabled(ctx)) {
       perf_debug("glCopyPixels(): Unsupported stencil test state\n");
       return false;
    }
 
    if (ctx->Fog.Enabled ||
        ctx->Texture._MaxEnabledTexImageUnit != -1 ||
        ctx->FragmentProgram._Enabled) {
       perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
       return false;
    }
diff --git a/src/mesa/drivers/dri/i965/brw_cc.c b/src/mesa/drivers/dri/i965/brw_cc.c
index 78d3bc8..f0aa7b8 100644
--- a/src/mesa/drivers/dri/i965/brw_cc.c
+++ b/src/mesa/drivers/dri/i965/brw_cc.c
@@ -65,55 +65,55 @@ brw_fix_xRGB_alpha(GLenum function)
  */
 static void upload_cc_unit(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
    struct brw_cc_unit_state *cc;
 
    cc = brw_state_batch(brw, sizeof(*cc), 64, &brw->cc.state_offset);
    memset(cc, 0, sizeof(*cc));
 
    /* _NEW_STENCIL | _NEW_BUFFERS */
-   if (ctx->Stencil._Enabled) {
+   if (brw->stencil_enabled) {
       const unsigned back = ctx->Stencil._BackFace;
 
       cc->cc0.stencil_enable = 1;
       cc->cc0.stencil_func =
 	 intel_translate_compare_func(ctx->Stencil.Function[0]);
       cc->cc0.stencil_fail_op =
 	 intel_translate_stencil_op(ctx->Stencil.FailFunc[0]);
       cc->cc0.stencil_pass_depth_fail_op =
 	 intel_translate_stencil_op(ctx->Stencil.ZFailFunc[0]);
       cc->cc0.stencil_pass_depth_pass_op =
 	 intel_translate_stencil_op(ctx->Stencil.ZPassFunc[0]);
       cc->cc1.stencil_ref = _mesa_get_stencil_ref(ctx, 0);
       cc->cc1.stencil_write_mask = ctx->Stencil.WriteMask[0];
       cc->cc1.stencil_test_mask = ctx->Stencil.ValueMask[0];
 
-      if (ctx->Stencil._TestTwoSide) {
+      if (brw->stencil_two_sided) {
 	 cc->cc0.bf_stencil_enable = 1;
 	 cc->cc0.bf_stencil_func =
 	    intel_translate_compare_func(ctx->Stencil.Function[back]);
 	 cc->cc0.bf_stencil_fail_op =
 	    intel_translate_stencil_op(ctx->Stencil.FailFunc[back]);
 	 cc->cc0.bf_stencil_pass_depth_fail_op =
 	    intel_translate_stencil_op(ctx->Stencil.ZFailFunc[back]);
 	 cc->cc0.bf_stencil_pass_depth_pass_op =
 	    intel_translate_stencil_op(ctx->Stencil.ZPassFunc[back]);
 	 cc->cc1.bf_stencil_ref = _mesa_get_stencil_ref(ctx, back);
 	 cc->cc2.bf_stencil_write_mask = ctx->Stencil.WriteMask[back];
 	 cc->cc2.bf_stencil_test_mask = ctx->Stencil.ValueMask[back];
       }
 
       /* Not really sure about this:
        */
       if (ctx->Stencil.WriteMask[0] ||
-	  (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[back]))
+	  (brw->stencil_two_sided && ctx->Stencil.WriteMask[back]))
 	 cc->cc0.stencil_write_enable = 1;
    }
 
    /* _NEW_COLOR */
    if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) {
       cc->cc2.logicop_enable = 1;
       cc->cc5.logicop_func = intel_translate_logic_op(ctx->Color.LogicOp);
    } else if (ctx->Color.BlendEnabled && !ctx->Color._AdvancedBlendMode) {
       GLenum eqRGB = ctx->Color.Blend[0].EquationRGB;
       GLenum eqA = ctx->Color.Blend[0].EquationA;
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..b5fd795 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -36,20 +36,21 @@
 #include "main/context.h"
 #include "main/fbobject.h"
 #include "main/extensions.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/points.h"
 #include "main/version.h"
 #include "main/vtxfmt.h"
 #include "main/texobj.h"
 #include "main/framebuffer.h"
+#include "main/stencil.h"
 
 #include "vbo/vbo_context.h"
 
 #include "drivers/common/driverfuncs.h"
 #include "drivers/common/meta.h"
 #include "utils.h"
 
 #include "brw_context.h"
 #include "brw_defines.h"
 #include "brw_blorp.h"
@@ -194,20 +195,27 @@ intel_update_state(struct gl_context * ctx)
    struct intel_texture_object *tex_obj;
    struct intel_renderbuffer *depth_irb;
 
    if (ctx->swrast_context)
       _swrast_InvalidateState(ctx, new_state);
 
    brw->NewGLState |= new_state;
 
    _mesa_unlock_context_textures(ctx);
 
+   if (new_state & (_NEW_STENCIL | _NEW_BUFFERS)) {
+      brw->stencil_enabled = _mesa_stencil_is_enabled(ctx);
+      brw->stencil_two_sided = _mesa_stencil_is_two_sided(ctx);
+      brw->stencil_write_enabled =
+         _mesa_stencil_is_write_enabled(ctx, brw->stencil_two_sided);
+   }
+
    intel_prepare_render(brw);
 
    /* Resolve the depth buffer's HiZ buffer. */
    depth_irb = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_DEPTH);
    if (depth_irb && depth_irb->mt) {
       intel_miptree_prepare_depth(brw, depth_irb->mt,
                                   depth_irb->mt_level,
                                   depth_irb->mt_layer,
                                   depth_irb->layer_count);
    }
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..38eeabd 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -753,20 +753,25 @@ struct brw_context
 
    /**
     * Some versions of Gen hardware don't do centroid interpolation correctly
     * on unlit pixels, causing incorrect values for derivatives near triangle
     * edges.  Enabling this flag causes the fragment shader to use
     * non-centroid interpolation for unlit pixels, at the expense of two extra
     * fragment shader instructions.
     */
    bool needs_unlit_centroid_workaround;
 
+   /** Derived stencil states. */
+   bool stencil_enabled;
+   bool stencil_two_sided;
+   bool stencil_write_enabled;
+
    struct isl_device isl_dev;
 
    struct blorp_context blorp;
 
    GLuint NewGLState;
    struct {
       struct brw_state_flags pipelines[BRW_NUM_PIPELINES];
    } state;
 
    enum brw_pipeline last_pipeline;
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 9e0e242..1e92bbd 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -384,21 +384,21 @@ brw_postdraw_set_buffers_need_resolve(struct brw_context *brw)
          intel_miptree_finish_depth(brw, depth_irb->mt,
                                     depth_irb->mt_level,
                                     depth_irb->mt_layer, 1,
                                     depth_written);
       }
       if (depth_written)
          brw_render_cache_set_add_bo(brw, depth_irb->mt->bo);
    }
 
    if (ctx->Extensions.ARB_stencil_texturing &&
-       stencil_irb && ctx->Stencil._WriteEnabled) {
+       stencil_irb && brw->stencil_write_enabled) {
       brw_render_cache_set_add_bo(brw, stencil_irb->mt->bo);
    }
 
    for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
       struct intel_renderbuffer *irb =
          intel_renderbuffer(fb->_ColorDrawBuffers[i]);
 
       if (!irb)
          continue;
      
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 6fac3c4..0c8eced 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -464,21 +464,21 @@ brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key)
       }
 
       /* _NEW_DEPTH */
       if (ctx->Depth.Test)
          lookup |= BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT;
 
       if (brw_depth_writes_enabled(brw))
          lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT;
 
       /* _NEW_STENCIL | _NEW_BUFFERS */
-      if (ctx->Stencil._Enabled) {
+      if (brw->stencil_enabled) {
          lookup |= BRW_WM_IZ_STENCIL_TEST_ENABLE_BIT;
 
          if (ctx->Stencil.WriteMask[0] ||
              ctx->Stencil.WriteMask[ctx->Stencil._BackFace])
             lookup |= BRW_WM_IZ_STENCIL_WRITE_ENABLE_BIT;
       }
       key->iz_lookup = lookup;
    }
 
    line_aa = BRW_WM_AA_NEVER;
diff --git a/src/mesa/drivers/dri/i965/gen7_misc_state.c b/src/mesa/drivers/dri/i965/gen7_misc_state.c
index 16b08ed..d078129 100644
--- a/src/mesa/drivers/dri/i965/gen7_misc_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_misc_state.c
@@ -101,21 +101,21 @@ gen7_emit_depth_stencil_hiz(struct brw_context *brw,
 
    /* _NEW_DEPTH, _NEW_STENCIL, _NEW_BUFFERS */
    BEGIN_BATCH(7);
    /* 3DSTATE_DEPTH_BUFFER dw0 */
    OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
 
    /* 3DSTATE_DEPTH_BUFFER dw1 */
    OUT_BATCH((depth_mt ? depth_mt->pitch - 1 : 0) |
              (depthbuffer_format << 18) |
              ((hiz ? 1 : 0) << 22) |
-             ((stencil_mt != NULL && ctx->Stencil._WriteEnabled) << 27) |
+             ((stencil_mt != NULL && brw->stencil_write_enabled) << 27) |
              (brw_depth_writes_enabled(brw) << 28) |
              (surftype << 29));
 
    /* 3DSTATE_DEPTH_BUFFER dw2 */
    if (depth_mt) {
       OUT_RELOC(depth_mt->bo,
 	        I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
 	        0);
    } else {
       OUT_BATCH(0);
diff --git a/src/mesa/drivers/dri/i965/gen8_depth_state.c b/src/mesa/drivers/dri/i965/gen8_depth_state.c
index 39a786c..384a991 100644
--- a/src/mesa/drivers/dri/i965/gen8_depth_state.c
+++ b/src/mesa/drivers/dri/i965/gen8_depth_state.c
@@ -212,21 +212,21 @@ gen8_emit_depth_stencil_hiz(struct brw_context *brw,
 
    lod = irb ? irb->mt_level - irb->mt->first_level : 0;
 
    if (mt) {
       width = mt->logical_width0;
       height = mt->logical_height0;
    }
 
    emit_depth_packets(brw, depth_mt, brw_depthbuffer_format(brw), surftype,
                       brw_depth_writes_enabled(brw),
-                      stencil_mt, ctx->Stencil._WriteEnabled,
+                      stencil_mt, brw->stencil_write_enabled,
                       hiz, width, height, depth, lod, min_array_element);
 }
 
 /**
  * Should we set the PMA FIX ENABLE bit?
  *
  * To avoid unnecessary depth related stalls, we need to set this bit.
  * However, there is a very complicated formula which governs when it
  * is legal to do so.  This function computes that.
  *
@@ -280,21 +280,21 @@ pma_fix_enable(const struct brw_context *brw)
     * 3DSTATE_WM_DEPTH_STENCIL::DepthWriteEnable &&
     * 3DSTATE_DEPTH_BUFFER::DEPTH_WRITE_ENABLE.
     */
    const bool depth_writes_enabled = brw_depth_writes_enabled(brw);
 
    /* _NEW_STENCIL:
     * !DEPTH_STENCIL_STATE::Stencil Buffer Write Enable ||
     * !3DSTATE_DEPTH_BUFFER::Stencil Buffer Enable ||
     * !3DSTATE_STENCIL_BUFFER::Stencil Buffer Enable
     */
-   const bool stencil_writes_enabled = ctx->Stencil._WriteEnabled;
+   const bool stencil_writes_enabled = brw->stencil_write_enabled;
 
    /* 3DSTATE_PS_EXTRA::Pixel Shader Computed Depth Mode != PSCDEPTH_OFF */
    const bool ps_computes_depth =
       wm_prog_data->computed_depth_mode != BRW_PSCDEPTH_OFF;
 
    /* BRW_NEW_FS_PROG_DATA:     3DSTATE_PS_EXTRA::PixelShaderKillsPixels
     * BRW_NEW_FS_PROG_DATA:     3DSTATE_PS_EXTRA::oMask Present to RenderTarget
     * _NEW_MULTISAMPLE:         3DSTATE_PS_BLEND::AlphaToCoverageEnable
     * _NEW_COLOR:               3DSTATE_PS_BLEND::AlphaTestEnable
     * _NEW_BUFFERS:             3DSTATE_PS_BLEND::AlphaTestEnable
@@ -333,21 +333,21 @@ gen8_write_pma_stall_bits(struct brw_context *brw, uint32_t pma_stall_bits)
       return;
 
    brw->pma_stall_bits = pma_stall_bits;
 
    /* According to the PIPE_CONTROL documentation, software should emit a
     * PIPE_CONTROL with the CS Stall and Depth Cache Flush bits set prior
     * to the LRI.  If stencil buffer writes are enabled, then a Render Cache
     * Flush is also necessary.
     */
    const uint32_t render_cache_flush =
-      ctx->Stencil._WriteEnabled ? PIPE_CONTROL_RENDER_TARGET_FLUSH : 0;
+      brw->stencil_write_enabled ? PIPE_CONTROL_RENDER_TARGET_FLUSH : 0;
    brw_emit_pipe_control_flush(brw,
                                PIPE_CONTROL_CS_STALL |
                                PIPE_CONTROL_DEPTH_CACHE_FLUSH |
                                render_cache_flush);
 
    /* CACHE_MODE_1 is a non-privileged register. */
    BEGIN_BATCH(3);
    OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
    OUT_BATCH(GEN7_CACHE_MODE_1);
    OUT_BATCH(GEN8_HIZ_PMA_MASK_BITS | pma_stall_bits);
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 0a32e46..6598f1f 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -1152,37 +1152,37 @@ genX(upload_depth_stencil_state)(struct brw_context *brw)
 #else
    uint32_t ds_offset;
    brw_state_emit(brw, GENX(DEPTH_STENCIL_STATE), 64, &ds_offset, wmds) {
 #endif
       if (depth->Test && depth_irb) {
          wmds.DepthTestEnable = true;
          wmds.DepthBufferWriteEnable = brw_depth_writes_enabled(brw);
          wmds.DepthTestFunction = intel_translate_compare_func(depth->Func);
       }
 
-      if (stencil->_Enabled) {
+      if (brw->stencil_enabled) {
          wmds.StencilTestEnable = true;
          wmds.StencilWriteMask = stencil->WriteMask[0] & 0xff;
          wmds.StencilTestMask = stencil->ValueMask[0] & 0xff;
 
          wmds.StencilTestFunction =
             intel_translate_compare_func(stencil->Function[0]);
          wmds.StencilFailOp =
             intel_translate_stencil_op(stencil->FailFunc[0]);
          wmds.StencilPassDepthPassOp =
             intel_translate_stencil_op(stencil->ZPassFunc[0]);
          wmds.StencilPassDepthFailOp =
             intel_translate_stencil_op(stencil->ZFailFunc[0]);
 
-         wmds.StencilBufferWriteEnable = stencil->_WriteEnabled;
+         wmds.StencilBufferWriteEnable = brw->stencil_write_enabled;
 
-         if (stencil->_TestTwoSide) {
+         if (brw->stencil_two_sided) {
             wmds.DoubleSidedStencilEnable = true;
             wmds.BackfaceStencilWriteMask = stencil->WriteMask[b] & 0xff;
             wmds.BackfaceStencilTestMask = stencil->ValueMask[b] & 0xff;
 
             wmds.BackfaceStencilTestFunction =
                intel_translate_compare_func(stencil->Function[b]);
             wmds.BackfaceStencilFailOp =
                intel_translate_stencil_op(stencil->FailFunc[b]);
             wmds.BackfaceStencilPassDepthPassOp =
                intel_translate_stencil_op(stencil->ZPassFunc[b]);
diff --git a/src/mesa/drivers/dri/i965/intel_pixel.c b/src/mesa/drivers/dri/i965/intel_pixel.c
index d4f86fd..e2babf8 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel.c
@@ -19,20 +19,21 @@
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  */
 
 #include "main/accum.h"
 #include "main/enums.h"
 #include "main/state.h"
+#include "main/stencil.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "swrast/swrast.h"
 
 #include "brw_context.h"
 #include "intel_pixel.h"
 
 #define FILE_DEBUG_FLAG DEBUG_PIXEL
 
 static GLenum
@@ -100,21 +101,21 @@ intel_check_blit_fragment_ops(struct gl_context * ctx, bool src_alpha_is_one)
    if (ctx->Fog.Enabled) {
       DBG("fallback due to fog\n");
       return false;
    }
 
    if (ctx->_ImageTransferState) {
       DBG("fallback due to image transfer\n");
       return false;
    }
 
-   if (ctx->Stencil._Enabled) {
+   if (_mesa_stencil_is_enabled(ctx)) {
       DBG("fallback due to image stencil\n");
       return false;
    }
 
    if (ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F) {
       DBG("fallback due to pixel zoom\n");
       return false;
    }
 
    if (ctx->RenderMode != GL_RENDER) {
diff --git a/src/mesa/drivers/dri/i965/intel_pixel_copy.c b/src/mesa/drivers/dri/i965/intel_pixel_copy.c
index 05c35bd..986707c 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel_copy.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel_copy.c
@@ -18,20 +18,21 @@
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  */
 
 #include "main/image.h"
 #include "main/state.h"
+#include "main/stencil.h"
 #include "main/mtypes.h"
 #include "main/condrender.h"
 #include "main/fbobject.h"
 #include "drivers/common/meta.h"
 
 #include "brw_context.h"
 #include "intel_buffers.h"
 #include "intel_mipmap_tree.h"
 #include "intel_pixel.h"
 #include "intel_fbo.h"
@@ -108,21 +109,21 @@ do_blit_copypixels(struct gl_context * ctx,
    if (ctx->_ImageTransferState) {
       perf_debug("glCopyPixels(): Unsupported image transfer state\n");
       return false;
    }
 
    if (ctx->Depth.Test) {
       perf_debug("glCopyPixels(): Unsupported depth test state\n");
       return false;
    }
 
-   if (ctx->Stencil._Enabled) {
+   if (brw->stencil_enabled) {
       perf_debug("glCopyPixels(): Unsupported stencil test state\n");
       return false;
    }
 
    if (ctx->Fog.Enabled ||
        ctx->Texture._MaxEnabledTexImageUnit != -1 ||
        ctx->FragmentProgram._Enabled) {
       perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
       return false;
    }
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_raster.c b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
index fbcc840..69664fb 100644
--- a/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
@@ -168,21 +168,21 @@ nv04_emit_control(struct gl_context *ctx, int emit)
 		nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE;
 	if (ctx->Color.ColorMask[0][BCOMP])
 		nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE;
 	if (ctx->Color.ColorMask[0][ACOMP])
 		nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE;
 
 	/* Stencil test. */
 	if (ctx->Stencil.WriteMask[0])
 		nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_STENCIL_WRITE;
 
-	if (ctx->Stencil._Enabled)
+	if (_mesa_stencil_is_enabled(ctx))
 		nv04->ctrl[1] |= NV04_MULTITEX_TRIANGLE_CONTROL1_STENCIL_ENABLE;
 
 	nv04->ctrl[1] |= get_comparison_op(ctx->Stencil.Function[0]) << 4 |
 			 _mesa_get_stencil_ref(ctx, 0) << 8 |
 			 ctx->Stencil.ValueMask[0] << 16 |
 			 ctx->Stencil.WriteMask[0] << 24;
 
 	nv04->ctrl[2] |= get_stencil_op(ctx->Stencil.ZPassFunc[0]) << 8 |
 			 get_stencil_op(ctx->Stencil.ZFailFunc[0]) << 4 |
 			 get_stencil_op(ctx->Stencil.FailFunc[0]);
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_raster.c b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
index ffde87a..d537f7b 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
@@ -138,21 +138,21 @@ nv10_emit_shade_model(struct gl_context *ctx, int emit)
 	PUSH_DATA (push, ctx->Light.ShadeModel == GL_SMOOTH ?
 		 NV10_3D_SHADE_MODEL_SMOOTH : NV10_3D_SHADE_MODEL_FLAT);
 }
 
 void
 nv10_emit_stencil_func(struct gl_context *ctx, int emit)
 {
 	struct nouveau_pushbuf *push = context_push(ctx);
 
 	BEGIN_NV04(push, NV10_3D(STENCIL_ENABLE), 1);
-	PUSH_DATAb(push, ctx->Stencil._Enabled);
+	PUSH_DATAb(push, _mesa_stencil_is_enabled(ctx));
 
 	BEGIN_NV04(push, NV10_3D(STENCIL_FUNC_FUNC), 3);
 	PUSH_DATA (push, nvgl_comparison_op(ctx->Stencil.Function[0]));
 	PUSH_DATA (push, _mesa_get_stencil_ref(ctx, 0));
 	PUSH_DATA (push, ctx->Stencil.ValueMask[0]);
 }
 
 void
 nv10_emit_stencil_mask(struct gl_context *ctx, int emit)
 {
diff --git a/src/mesa/drivers/dri/radeon/radeon_common.c b/src/mesa/drivers/dri/radeon/radeon_common.c
index ee4d5f8..6e4b4c4 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common.c
+++ b/src/mesa/drivers/dri/radeon/radeon_common.c
@@ -299,21 +299,20 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 		ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
 	else
 		ctx->NewState |= _NEW_POLYGON;
 
 	/*
 	 * Update depth test state
 	 */
 	if (ctx->Driver.Enable) {
 		ctx->Driver.Enable(ctx, GL_DEPTH_TEST,
 				   (ctx->Depth.Test && fb->Visual.depthBits > 0));
-		/* Need to update the derived ctx->Stencil._Enabled first */
 		ctx->Driver.Enable(ctx, GL_STENCIL_TEST,
 				   (ctx->Stencil.Enabled && fb->Visual.stencilBits > 0));
 	} else {
 		ctx->NewState |= (_NEW_DEPTH | _NEW_STENCIL);
 	}
 
 	_mesa_reference_renderbuffer(&radeon->state.depth.rb, &rrbDepth->base.Base);
 	_mesa_reference_renderbuffer(&radeon->state.color.rb, &rrbColor->base.Base);
 	radeon->state.color.draw_offset = offset;
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 21ddf57..1e02ff0 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -845,23 +845,20 @@ struct gl_scissor_attrib
  * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
  *
  * The derived value \c _TestTwoSide is set when the front-face and back-face
  * stencil state are different.
  */
 struct gl_stencil_attrib
 {
    GLboolean Enabled;		/**< Enabled flag */
    GLboolean TestTwoSide;	/**< GL_EXT_stencil_two_side */
    GLubyte ActiveFace;		/**< GL_EXT_stencil_two_side (0 or 2) */
-   GLboolean _Enabled;          /**< Enabled and stencil buffer present */
-   GLboolean _WriteEnabled;     /**< _Enabled and non-zero writemasks */
-   GLboolean _TestTwoSide;
    GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
    GLenum Function[3];		/**< Stencil function */
    GLenum FailFunc[3];		/**< Fail function */
    GLenum ZPassFunc[3];		/**< Depth buffer pass function */
    GLenum ZFailFunc[3];		/**< Depth buffer fail function */
    GLint Ref[3];		/**< Reference value */
    GLuint ValueMask[3];		/**< Value mask */
    GLuint WriteMask[3];		/**< Write mask */
    GLuint Clear;		/**< Clear value */
 };
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index b7e165f..d1d0c2c 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -372,23 +372,20 @@ _mesa_update_state_locked( struct gl_context *ctx )
 
    if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
       _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
 
    if (new_state & _NEW_LIGHT)
       _mesa_update_lighting( ctx );
 
    if (new_state & (_NEW_LIGHT | _NEW_PROGRAM))
       update_twoside( ctx );
 
-   if (new_state & (_NEW_STENCIL | _NEW_BUFFERS))
-      _mesa_update_stencil( ctx );
-
    if (new_state & _NEW_PIXEL)
       _mesa_update_pixel( ctx );
 
    /* ctx->_NeedEyeCoords is now up to date.
     *
     * If the truth value of this variable has changed, update for the
     * new lighting space and recompute the positions of lights and the
     * normal transform.
     *
     * If the lighting space hasn't changed, may still need to recompute
diff --git a/src/mesa/main/stencil.c b/src/mesa/main/stencil.c
index b303bb7..2547f45 100644
--- a/src/mesa/main/stencil.c
+++ b/src/mesa/main/stencil.c
@@ -508,48 +508,20 @@ _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
    if (face != GL_FRONT) {
       ctx->Stencil.WriteMask[1] = mask;
    }
    if (ctx->Driver.StencilMaskSeparate) {
       ctx->Driver.StencilMaskSeparate(ctx, face, mask);
    }
 }
 
 
 /**
- * Update derived stencil state.
- */
-void
-_mesa_update_stencil(struct gl_context *ctx)
-{
-   const GLint face = ctx->Stencil._BackFace;
-
-   ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
-                            ctx->DrawBuffer->Visual.stencilBits > 0);
-
-    ctx->Stencil._TestTwoSide =
-       ctx->Stencil._Enabled &&
-       (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
-	ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
-	ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
-	ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
-	ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
-	ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
-	ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
-
-   ctx->Stencil._WriteEnabled =
-      ctx->Stencil._Enabled &&
-      (ctx->Stencil.WriteMask[0] != 0 ||
-       (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[face] != 0));
-}
-
-
-/**
  * Initialize the context stipple state.
  *
  * \param ctx GL context.
  *
  * Initializes __struct gl_contextRec::Stencil attribute group.
  */
 void
 _mesa_init_stencil(struct gl_context *ctx)
 {
    ctx->Stencil.Enabled = GL_FALSE;
diff --git a/src/mesa/main/stencil.h b/src/mesa/main/stencil.h
index 3302cb9..74ea5ef 100644
--- a/src/mesa/main/stencil.h
+++ b/src/mesa/main/stencil.h
@@ -64,33 +64,59 @@ _mesa_StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
 extern void GLAPIENTRY
 _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
 
 
 extern void GLAPIENTRY
 _mesa_StencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
 
 extern void GLAPIENTRY
 _mesa_StencilMaskSeparate(GLenum face, GLuint mask);
 
-
-extern void
-_mesa_update_stencil(struct gl_context *ctx);
-
-
 extern void 
 _mesa_init_stencil( struct gl_context * ctx );
 
 /* From the GL 4.3 spec, 17.3.5:
  *    "Stencil comparison operations and queries of <ref> clamp its value
  *    to the range [0, 2^s-1], where <s> is the number of bits in the
  *    stencil buffer attached to the draw framebuffer."
  */
 
 static inline GLint
 _mesa_get_stencil_ref(struct gl_context const *ctx, int face)
 {
    GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
    GLint ref = ctx->Stencil.Ref[face];
    return CLAMP(ref, 0, stencilMax);
 }
 
+static inline bool
+_mesa_stencil_is_enabled(const struct gl_context *ctx)
+{
+   return ctx->Stencil.Enabled &&
+          ctx->DrawBuffer->Visual.stencilBits > 0;
+}
+
+static inline bool
+_mesa_stencil_is_two_sided(const struct gl_context *ctx)
+{
+   const int face = ctx->Stencil._BackFace;
+
+   return _mesa_stencil_is_enabled(ctx) &&
+          (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
+           ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
+           ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
+           ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
+           ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
+           ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
+           ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
+}
+
+static inline bool
+_mesa_stencil_is_write_enabled(const struct gl_context *ctx, bool is_two_sided)
+{
+   return _mesa_stencil_is_enabled(ctx) &&
+          (ctx->Stencil.WriteMask[0] != 0 ||
+           (is_two_sided &&
+            ctx->Stencil.WriteMask[ctx->Stencil._BackFace] != 0));
+}
+
 #endif
diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c
index 432de4b..3b2beaf 100644
--- a/src/mesa/state_tracker/st_atom_depth.c
+++ b/src/mesa/state_tracker/st_atom_depth.c
@@ -121,21 +121,21 @@ st_update_depth_stencil_alpha(struct st_context *st)
    if (ctx->Stencil.Enabled && ctx->DrawBuffer->Visual.stencilBits > 0) {
       dsa->stencil[0].enabled = 1;
       dsa->stencil[0].func = st_compare_func_to_pipe(ctx->Stencil.Function[0]);
       dsa->stencil[0].fail_op = gl_stencil_op_to_pipe(ctx->Stencil.FailFunc[0]);
       dsa->stencil[0].zfail_op = gl_stencil_op_to_pipe(ctx->Stencil.ZFailFunc[0]);
       dsa->stencil[0].zpass_op = gl_stencil_op_to_pipe(ctx->Stencil.ZPassFunc[0]);
       dsa->stencil[0].valuemask = ctx->Stencil.ValueMask[0] & 0xff;
       dsa->stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
       sr.ref_value[0] = _mesa_get_stencil_ref(ctx, 0);
 
-      if (ctx->Stencil._TestTwoSide) {
+      if (_mesa_stencil_is_two_sided(ctx)) {
          const GLuint back = ctx->Stencil._BackFace;
          dsa->stencil[1].enabled = 1;
          dsa->stencil[1].func = st_compare_func_to_pipe(ctx->Stencil.Function[back]);
          dsa->stencil[1].fail_op = gl_stencil_op_to_pipe(ctx->Stencil.FailFunc[back]);
          dsa->stencil[1].zfail_op = gl_stencil_op_to_pipe(ctx->Stencil.ZFailFunc[back]);
          dsa->stencil[1].zpass_op = gl_stencil_op_to_pipe(ctx->Stencil.ZPassFunc[back]);
          dsa->stencil[1].valuemask = ctx->Stencil.ValueMask[back] & 0xff;
          dsa->stencil[1].writemask = ctx->Stencil.WriteMask[back] & 0xff;
          sr.ref_value[1] = _mesa_get_stencil_ref(ctx, back);
       }
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 9cb03b3..71389c6 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -22,20 +22,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com> Brian Paul
  */
 
 #include "main/imports.h"
 #include "main/bufferobj.h"
 #include "main/mtypes.h"
 #include "main/samplerobj.h"
+#include "main/stencil.h"
 #include "main/teximage.h"
 #include "program/prog_parameter.h"
 #include "program/prog_statevars.h"
 #include "swrast.h"
 #include "s_blend.h"
 #include "s_context.h"
 #include "s_lines.h"
 #include "s_points.h"
 #include "s_span.h"
 #include "s_texfetch.h"
@@ -54,21 +55,21 @@ _swrast_update_rasterflags( struct gl_context *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLbitfield rasterMask = 0;
    GLuint i;
 
    if (ctx->Color.AlphaEnabled)           rasterMask |= ALPHATEST_BIT;
    if (ctx->Color.BlendEnabled)           rasterMask |= BLEND_BIT;
    if (ctx->Depth.Test)                   rasterMask |= DEPTH_BIT;
    if (swrast->_FogEnabled)               rasterMask |= FOG_BIT;
    if (ctx->Scissor.EnableFlags)          rasterMask |= CLIP_BIT;
-   if (ctx->Stencil._Enabled)             rasterMask |= STENCIL_BIT;
+   if (_mesa_stencil_is_enabled(ctx))     rasterMask |= STENCIL_BIT;
    for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
       if (!ctx->Color.ColorMask[i][0] ||
           !ctx->Color.ColorMask[i][1] ||
           !ctx->Color.ColorMask[i][2] ||
           !ctx->Color.ColorMask[i][3]) {
          rasterMask |= MASKING_BIT;
          break;
       }
    }
    if (ctx->Color.ColorLogicOpEnabled) rasterMask |= LOGIC_OP_BIT;
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 49fc580..8183563 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -32,20 +32,21 @@
  */
 
 #include "c99_math.h"
 #include "main/glheader.h"
 #include "main/format_pack.h"
 #include "main/format_unpack.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/samplerobj.h"
+#include "main/stencil.h"
 #include "main/teximage.h"
 
 #include "s_atifragshader.h"
 #include "s_alpha.h"
 #include "s_blend.h"
 #include "s_context.h"
 #include "s_depth.h"
 #include "s_fog.h"
 #include "s_logic.h"
 #include "s_masking.h"
@@ -1206,28 +1207,28 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
    /* Do the alpha test */
    if (ctx->Color.AlphaEnabled) {
       if (!_swrast_alpha_test(ctx, span)) {
          /* all fragments failed test */
          goto end;
       }
    }
 
    /* Stencil and Z testing */
-   if (ctx->Stencil._Enabled || ctx->Depth.Test) {
+   if (_mesa_stencil_is_enabled(ctx) || ctx->Depth.Test) {
       if (!(span->arrayMask & SPAN_Z))
          _swrast_span_interpolate_z(ctx, span);
 
       if (ctx->Transform.DepthClamp)
 	 _swrast_depth_clamp_span(ctx, span);
 
-      if (ctx->Stencil._Enabled) {
+      if (_mesa_stencil_is_enabled(ctx)) {
          /* Combined Z/stencil tests */
          if (!_swrast_stencil_and_ztest_span(ctx, span)) {
             /* all fragments failed test */
             goto end;
          }
       }
       else if (fb->Visual.depthBits > 0) {
          /* Just regular depth testing */
          assert(ctx->Depth.Test);
          assert(span->arrayMask & SPAN_Z);
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 876a74b..9e4f81e 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -29,20 +29,21 @@
  * functions to draw triangles.
  */
 
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/state.h"
 #include "main/samplerobj.h"
+#include "main/stencil.h"
 #include "main/teximage.h"
 #include "program/prog_instruction.h"
 
 #include "s_aatriangle.h"
 #include "s_context.h"
 #include "s_feedback.h"
 #include "s_span.h"
 #include "s_triangle.h"
 
 
@@ -1016,21 +1017,21 @@ _swrast_choose_triangle( struct gl_context *ctx )
          _swrast_set_aa_triangle_function(ctx);
          assert(swrast->Triangle);
          return;
       }
 
       /* special case for occlusion testing */
       if (ctx->Query.CurrentOcclusionObject &&
           ctx->Depth.Test &&
           ctx->Depth.Mask == GL_FALSE &&
           ctx->Depth.Func == GL_LESS &&
-          !ctx->Stencil._Enabled &&
+          !_mesa_stencil_is_enabled(ctx) &&
           depthRb &&
           depthRb->Format == MESA_FORMAT_Z_UNORM16) {
          if (ctx->Color.ColorMask[0][0] == 0 &&
 	     ctx->Color.ColorMask[0][1] == 0 &&
 	     ctx->Color.ColorMask[0][2] == 0 &&
 	     ctx->Color.ColorMask[0][3] == 0) {
             USE(occlusion_zless_16_triangle);
             return;
          }
       }
diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c
index b92c20b..8f034d8 100644
--- a/src/mesa/swrast_setup/ss_triangle.c
+++ b/src/mesa/swrast_setup/ss_triangle.c
@@ -22,20 +22,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 #include "c99_math.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
+#include "main/stencil.h"
 
 #include "tnl/t_context.h"
 
 #include "ss_triangle.h"
 #include "ss_context.h"
 
 #define SS_OFFSET_BIT	    0x1
 #define SS_TWOSIDE_BIT	    0x2
 #define SS_UNFILLED_BIT	    0x4
 #define SS_MAX_TRIFUNC      0x8
@@ -248,18 +249,18 @@ void _swsetup_choose_trifuncs( struct gl_context *ctx )
 
    if ((ctx->Light.Enabled && ctx->Light.Model.TwoSide) ||
        (ctx->VertexProgram._Current && ctx->VertexProgram.TwoSideEnabled))
       ind |= SS_TWOSIDE_BIT;
 
    /* We piggyback the two-sided stencil front/back determination on the
     * unfilled triangle path.
     */
    if (ctx->Polygon.FrontMode != GL_FILL ||
        ctx->Polygon.BackMode != GL_FILL ||
-       (ctx->Stencil.Enabled && ctx->Stencil._TestTwoSide))
+       (ctx->Stencil.Enabled && _mesa_stencil_is_two_sided(ctx)))
       ind |= SS_UNFILLED_BIT;
 
    tnl->Driver.Render.Triangle = tri_tab[ind];
    tnl->Driver.Render.Quad = quad_tab[ind];
    tnl->Driver.Render.Line = swsetup_line;
    tnl->Driver.Render.Points = swsetup_points;
 }
-- 
2.7.4



More information about the mesa-dev mailing list