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);
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 |
#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"
return false;
}
- if (ctx->Stencil._Enabled) {
+ if (_mesa_stencil_is_enabled(ctx)) {
DBG("fallback due to image stencil\n");
return false;
}
#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"
return false;
}
- if (ctx->Stencil._Enabled) {
+ if (_mesa_stencil_is_enabled(ctx)) {
perf_debug("glCopyPixels(): Unsupported stencil test state\n");
return false;
}
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->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]);
/* 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;
}
#include "main/vtxfmt.h"
#include "main/texobj.h"
#include "main/framebuffer.h"
+#include "main/stencil.h"
#include "vbo/vbo_context.h"
_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. */
*/
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;
}
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);
}
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] ||
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));
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);
}
* !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 =
* 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 |
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.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;
#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"
return false;
}
- if (ctx->Stencil._Enabled) {
+ if (_mesa_stencil_is_enabled(ctx)) {
DBG("fallback due to image stencil\n");
return false;
}
#include "main/image.h"
#include "main/state.h"
+#include "main/stencil.h"
#include "main/mtypes.h"
#include "main/condrender.h"
#include "main/fbobject.h"
return false;
}
- if (ctx->Stencil._Enabled) {
+ if (brw->stencil_enabled) {
perf_debug("glCopyPixels(): Unsupported stencil test state\n");
return false;
}
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 |
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]));
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 {
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 */
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 );
}
-/**
- * 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.
*
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 );
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
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]);
#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"
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] ||
#include "main/imports.h"
#include "main/image.h"
#include "main/samplerobj.h"
+#include "main/stencil.h"
#include "main/teximage.h"
#include "s_atifragshader.h"
}
/* 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 */
#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"
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 &&
#include "main/glheader.h"
#include "main/macros.h"
#include "main/mtypes.h"
+#include "main/stencil.h"
#include "tnl/t_context.h"
*/
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];