From 5d187e9cade0f67c7fa77dcae43d264619297574 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 7 Apr 2022 10:40:44 -0400 Subject: [PATCH] panfrost: Add helpers to set batch masks This logic is not device specific and will be used for both Bifrost and Valhall. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_context.h | 6 +++ src/gallium/drivers/panfrost/pan_helpers.c | 50 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 4f58e4456a1..db3d8bff117 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -418,4 +418,10 @@ panfrost_clean_state_3d(struct panfrost_context *ctx) } } +void +panfrost_set_batch_masks_blend(struct panfrost_batch *batch); + +void +panfrost_set_batch_masks_zs(struct panfrost_batch *batch); + #endif diff --git a/src/gallium/drivers/panfrost/pan_helpers.c b/src/gallium/drivers/panfrost/pan_helpers.c index 69331d06795..90fc64058eb 100644 --- a/src/gallium/drivers/panfrost/pan_helpers.c +++ b/src/gallium/drivers/panfrost/pan_helpers.c @@ -169,3 +169,53 @@ pan_assign_vertex_buffer(struct pan_vertex_buffer *buffers, return idx; } +/* + * Helper to add a PIPE_CLEAR_* to batch->draws and batch->resolve together, + * meaning that we draw to a given target. Adding to only one mask does not + * generally make sense, except for clears which add to batch->clear and + * batch->resolve together. + */ +static void +panfrost_draw_target(struct panfrost_batch *batch, unsigned target) +{ + batch->draws |= target; + batch->resolve |= target; +} + +/* + * Draw time helper to set batch->{read, draws, resolve} based on current blend + * and depth-stencil state. To be called when blend or depth/stencil dirty state + * respectively changes. + */ +void +panfrost_set_batch_masks_blend(struct panfrost_batch *batch) +{ + struct panfrost_context *ctx = batch->ctx; + struct panfrost_blend_state *blend = ctx->blend; + + for (unsigned i = 0; i < batch->key.nr_cbufs; ++i) { + if (!blend->info[i].no_colour && batch->key.cbufs[i]) + panfrost_draw_target(batch, PIPE_CLEAR_COLOR0 << i); + } +} + +void +panfrost_set_batch_masks_zs(struct panfrost_batch *batch) +{ + struct panfrost_context *ctx = batch->ctx; + struct pipe_depth_stencil_alpha_state *zsa = (void *) ctx->depth_stencil; + + /* Assume depth is read (TODO: perf) */ + if (zsa->depth_enabled) + batch->read |= PIPE_CLEAR_DEPTH; + + if (zsa->depth_writemask) + panfrost_draw_target(batch, PIPE_CLEAR_DEPTH); + + if (zsa->stencil[0].enabled) { + panfrost_draw_target(batch, PIPE_CLEAR_STENCIL); + + /* Assume stencil is read (TODO: perf) */ + batch->read |= PIPE_CLEAR_STENCIL; + } +}