return tu_cs_end_draw_state(&cmd->sub_cs, &cs);
}
-static bool
-tu6_writes_depth(struct tu_cmd_buffer *cmd, bool depth_test_enable)
-{
- bool depth_write_enable =
- cmd->state.rb_depth_cntl & A6XX_RB_DEPTH_CNTL_Z_WRITE_ENABLE;
-
- VkCompareOp depth_compare_op =
- (cmd->state.rb_depth_cntl & A6XX_RB_DEPTH_CNTL_ZFUNC__MASK) >> A6XX_RB_DEPTH_CNTL_ZFUNC__SHIFT;
-
- bool depth_compare_op_writes = depth_compare_op != VK_COMPARE_OP_NEVER;
-
- return depth_test_enable && depth_write_enable && depth_compare_op_writes;
-}
-
-static bool
-tu6_writes_stencil(struct tu_cmd_buffer *cmd)
+/* Various frontends (ANGLE, zink at least) will enable stencil testing with
+ * what works out to be no-op writes. Simplify what they give us into flags
+ * that LRZ can use.
+ */
+static void
+tu6_update_simplified_stencil_state(struct tu_cmd_buffer *cmd)
{
bool stencil_test_enable =
cmd->state.rb_stencil_cntl & A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE;
+ if (!stencil_test_enable) {
+ cmd->state.stencil_front_write = false;
+ cmd->state.stencil_back_write = false;
+ return;
+ }
+
bool stencil_front_writemask =
(cmd->state.pipeline->dynamic_state_mask & BIT(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) ?
(cmd->state.dynamic_stencil_wrmask & 0xff) :
back_fail_op != VK_STENCIL_OP_KEEP ||
back_depth_fail_op != VK_STENCIL_OP_KEEP;
- return stencil_test_enable &&
- ((stencil_front_writemask && stencil_front_op_writes) ||
- (stencil_back_writemask && stencil_back_op_writes));
+ cmd->state.stencil_front_write =
+ stencil_front_op_writes && stencil_front_writemask;
+ cmd->state.stencil_back_write =
+ stencil_back_op_writes && stencil_back_writemask;
+}
+
+static bool
+tu6_writes_depth(struct tu_cmd_buffer *cmd, bool depth_test_enable)
+{
+ bool depth_write_enable =
+ cmd->state.rb_depth_cntl & A6XX_RB_DEPTH_CNTL_Z_WRITE_ENABLE;
+
+ VkCompareOp depth_compare_op =
+ (cmd->state.rb_depth_cntl & A6XX_RB_DEPTH_CNTL_ZFUNC__MASK) >> A6XX_RB_DEPTH_CNTL_ZFUNC__SHIFT;
+
+ bool depth_compare_op_writes = depth_compare_op != VK_COMPARE_OP_NEVER;
+
+ return depth_test_enable && depth_write_enable && depth_compare_op_writes;
+}
+
+static bool
+tu6_writes_stencil(struct tu_cmd_buffer *cmd)
+{
+ return cmd->state.stencil_front_write || cmd->state.stencil_back_write;
}
static void
cmd->state.lrz_and_depth_plane_state =
tu_cs_draw_state(&cmd->sub_cs, &cs, size);
+ tu6_update_simplified_stencil_state(cmd);
tu6_emit_lrz(cmd, &cs);
tu6_build_depth_plane_z_mode(cmd, &cs);
}
/* Invalidate LRZ and disable write if stencil test is enabled */
bool stencil_test_enable = cmd->state.rb_stencil_cntl & A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE;
if (!disable_lrz && stencil_test_enable) {
- bool stencil_front_writemask =
- (pipeline->dynamic_state_mask & BIT(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) ?
- (cmd->state.dynamic_stencil_wrmask & 0xff) :
- (pipeline->ds.stencil_wrmask & 0xff);
-
- bool stencil_back_writemask =
- (pipeline->dynamic_state_mask & BIT(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) ?
- ((cmd->state.dynamic_stencil_wrmask & 0xff00) >> 8) :
- (pipeline->ds.stencil_wrmask & 0xff00) >> 8;
-
VkCompareOp stencil_front_compare_op =
(cmd->state.rb_stencil_cntl & A6XX_RB_STENCIL_CONTROL_FUNC__MASK) >> A6XX_RB_STENCIL_CONTROL_FUNC__SHIFT;
bool lrz_allowed = true;
lrz_allowed = lrz_allowed && tu6_stencil_op_lrz_allowed(
&gras_lrz_cntl, stencil_front_compare_op,
- stencil_front_writemask);
+ cmd->state.stencil_front_write);
lrz_allowed = lrz_allowed && tu6_stencil_op_lrz_allowed(
&gras_lrz_cntl, stencil_back_compare_op,
- stencil_back_writemask);
+ cmd->state.stencil_back_write);
/* Without depth write it's enough to make sure that depth test
* is executed after stencil test, so temporary disabling LRZ is enough.