From 358f40ea90b78aa22e679fd30413769776280df8 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 19 Nov 2024 12:25:35 -0400 Subject: [PATCH] panfrost: switch to u_tristate Signed-off-by: Alyssa Rosenzweig Reviewed-by: Eric Engestrom Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 6 +-- src/gallium/drivers/panfrost/pan_csf.c | 2 +- src/gallium/drivers/panfrost/pan_jm.c | 2 +- src/gallium/drivers/panfrost/pan_job.c | 7 +-- src/gallium/drivers/panfrost/pan_job.h | 53 ++------------------ 5 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 0ddaf166934..51e9ca0103a 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -3024,7 +3024,7 @@ panfrost_compatible_batch_state(struct panfrost_batch *batch, struct pipe_rasterizer_state *rast = &ctx->rasterizer->base; if (reduced_prim == MESA_PRIM_LINES && - !pan_tristate_set(&batch->line_smoothing, rast->line_smooth)) + !u_tristate_set(&batch->line_smoothing, rast->line_smooth)) return false; /* Only applies on Valhall */ @@ -3038,9 +3038,9 @@ panfrost_compatible_batch_state(struct panfrost_batch *batch, * provoking vertex doesn't matter for points. */ if (reduced_prim == MESA_PRIM_POINTS) - return pan_tristate_set(&batch->sprite_coord_origin, coord); + return u_tristate_set(&batch->sprite_coord_origin, coord); else - return pan_tristate_set(&batch->first_provoking_vertex, first); + return u_tristate_set(&batch->first_provoking_vertex, first); } static struct panfrost_batch * diff --git a/src/gallium/drivers/panfrost/pan_csf.c b/src/gallium/drivers/panfrost/pan_csf.c index e2a17884595..d9f0fa47d0c 100644 --- a/src/gallium/drivers/panfrost/pan_csf.c +++ b/src/gallium/drivers/panfrost/pan_csf.c @@ -961,7 +961,7 @@ csf_get_tiler_desc(struct panfrost_batch *batch) tiler.sample_pattern = pan_sample_pattern(util_framebuffer_get_num_samples(&batch->key)); tiler.first_provoking_vertex = - pan_tristate_get(batch->first_provoking_vertex); + batch->first_provoking_vertex == U_TRISTATE_YES; tiler.geometry_buffer = ctx->csf.tmp_geom_bo->ptr.gpu; tiler.geometry_buffer_size = ctx->csf.tmp_geom_bo->kmod_bo->size; } diff --git a/src/gallium/drivers/panfrost/pan_jm.c b/src/gallium/drivers/panfrost/pan_jm.c index ebcf740fb31..d220efe4b6e 100644 --- a/src/gallium/drivers/panfrost/pan_jm.c +++ b/src/gallium/drivers/panfrost/pan_jm.c @@ -435,7 +435,7 @@ jm_emit_tiler_desc(struct panfrost_batch *batch) pan_sample_pattern(util_framebuffer_get_num_samples(&batch->key)); #if PAN_ARCH >= 9 tiler.first_provoking_vertex = - pan_tristate_get(batch->first_provoking_vertex); + batch->first_provoking_vertex == U_TRISTATE_YES; #endif } diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index eaa79383feb..a0834bae180 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -468,10 +468,11 @@ panfrost_batch_to_fb_info(const struct panfrost_batch *batch, fb->extent.maxx = batch->maxx - 1; fb->extent.maxy = batch->maxy - 1; fb->nr_samples = util_framebuffer_get_num_samples(&batch->key); - fb->force_samples = pan_tristate_get(batch->line_smoothing) ? 16 : 0; + fb->force_samples = (batch->line_smoothing == U_TRISTATE_YES) ? 16 : 0; fb->rt_count = batch->key.nr_cbufs; - fb->sprite_coord_origin = pan_tristate_get(batch->sprite_coord_origin); - fb->first_provoking_vertex = pan_tristate_get(batch->first_provoking_vertex); + fb->sprite_coord_origin = (batch->sprite_coord_origin == U_TRISTATE_YES); + fb->first_provoking_vertex = + (batch->first_provoking_vertex == U_TRISTATE_YES); static const unsigned char id_swz[] = { PIPE_SWIZZLE_X, diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h index 5c6a917960f..df1e65572f5 100644 --- a/src/gallium/drivers/panfrost/pan_job.h +++ b/src/gallium/drivers/panfrost/pan_job.h @@ -28,58 +28,13 @@ #include "pipe/p_state.h" #include "util/u_dynarray.h" +#include "util/u_tristate.h" #include "pan_csf.h" #include "pan_desc.h" #include "pan_jm.h" #include "pan_mempool.h" #include "pan_resource.h" -/* Simple tri-state data structure. In the default "don't care" state, the value - * may be set to true or false. However, once the value is set, it must not be - * changed. Declared inside of a struct to prevent casting to bool, which is an - * error. The getter needs to be used instead. - */ -struct pan_tristate { - enum { - PAN_TRISTATE_DONTCARE, - PAN_TRISTATE_FALSE, - PAN_TRISTATE_TRUE, - } v; -}; - -/* - * Try to set a tristate value to a desired boolean value. Returns whether the - * operation is successful. - */ -static inline bool -pan_tristate_set(struct pan_tristate *state, bool value) -{ - switch (state->v) { - case PAN_TRISTATE_DONTCARE: - state->v = value ? PAN_TRISTATE_TRUE : PAN_TRISTATE_FALSE; - return true; - - case PAN_TRISTATE_FALSE: - return (value == false); - - case PAN_TRISTATE_TRUE: - return (value == true); - - default: - unreachable("Invalid tristate value"); - } -} - -/* - * Read the boolean value of a tristate. Return value undefined in the don't - * care state. - */ -static inline bool -pan_tristate_get(struct pan_tristate state) -{ - return (state.v == PAN_TRISTATE_TRUE); -} - /* A panfrost_batch corresponds to a bound FBO we're rendering to, * collecting over multiple draws. */ @@ -207,11 +162,11 @@ struct panfrost_batch { /* On Valhall, these are properties of the batch. On Bifrost, they are * per draw. */ - struct pan_tristate sprite_coord_origin; - struct pan_tristate first_provoking_vertex; + enum u_tristate sprite_coord_origin; + enum u_tristate first_provoking_vertex; /** This one is always on the batch */ - struct pan_tristate line_smoothing; + enum u_tristate line_smoothing; /* Number of effective draws in the batch. Draws with rasterization disabled * don't count as effective draws. It's basically the number of IDVS or