From 7277342b5e8a0a83045621ac77d2c54f9861353f Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 20 Jan 2021 10:27:55 -0800 Subject: [PATCH] gallium/util: Add helpers to determine if z/s is written For drivers that must control various 'early-z'-like state, it is easy enough to get this wrong. So add helpers so we don't have to duplicate the logic in each driver. Signed-off-by: Rob Clark Reviewed-by: Eric Anholt Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/auxiliary/util/u_inlines.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e79e977a441..c5aadc7ca18 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -763,6 +763,26 @@ util_logicop_reads_dest(enum pipe_logicop op) unreachable("bad logicop"); } +static inline bool +util_writes_stencil(const struct pipe_stencil_state *s) +{ + return s->enabled && s->writemask && + ((s->fail_op != PIPE_STENCIL_OP_KEEP) || + (s->zpass_op != PIPE_STENCIL_OP_KEEP) || + (s->zfail_op != PIPE_STENCIL_OP_KEEP)); +} + +static inline bool +util_writes_depth_stencil(const struct pipe_depth_stencil_alpha_state *zsa) +{ + if (zsa->depth_enabled && zsa->depth_writemask && + (zsa->depth_func != PIPE_FUNC_NEVER)) + return true; + + return util_writes_stencil(&zsa->stencil[0]) || + util_writes_stencil(&zsa->stencil[1]); +} + static inline struct pipe_context * pipe_create_multimedia_context(struct pipe_screen *screen) {