From ae2b9112174985af2de213c928afc4b7fde630c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 21 Nov 2022 07:59:14 -0500 Subject: [PATCH] st/mesa: inline st_validate_state and remove redundant checking in callers Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/buffers.c | 1 + src/mesa/main/compute.c | 5 +---- src/mesa/main/fbobject.c | 1 + src/mesa/main/multisample.c | 2 +- src/mesa/state_tracker/st_atom.c | 38 ++++---------------------------- src/mesa/state_tracker/st_atom.h | 6 ++++- src/mesa/state_tracker/st_cb_bitmap.c | 5 +---- src/mesa/state_tracker/st_cb_rasterpos.c | 1 + src/mesa/state_tracker/st_draw.c | 4 +--- src/mesa/state_tracker/st_util.h | 24 ++++++++++++++++++++ 10 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 169987a..13a0116 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -46,6 +46,7 @@ #include "state_tracker/st_manager.h" #include "state_tracker/st_atom.h" #include "state_tracker/st_context.h" +#include "state_tracker/st_util.h" #define BAD_MASK ~0u diff --git a/src/mesa/main/compute.c b/src/mesa/main/compute.c index c0ba026..e601f19 100644 --- a/src/mesa/main/compute.c +++ b/src/mesa/main/compute.c @@ -295,10 +295,7 @@ prepare_compute(struct gl_context *ctx) if (ctx->NewState) _mesa_update_state(ctx); - if (ctx->NewDriverState & st->active_states & - ST_PIPELINE_COMPUTE_STATE_MASK) - st_validate_state(st, ST_PIPELINE_COMPUTE_STATE_MASK); - + st_validate_state(st, ST_PIPELINE_COMPUTE_STATE_MASK); } static ALWAYS_INLINE void diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index be1a8dd..65562e7 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -56,6 +56,7 @@ #include "state_tracker/st_cb_eglimage.h" #include "state_tracker/st_context.h" #include "state_tracker/st_format.h" +#include "state_tracker/st_util.h" /** * Notes: diff --git a/src/mesa/main/multisample.c b/src/mesa/main/multisample.c index e5f9f0a..801a997 100644 --- a/src/mesa/main/multisample.c +++ b/src/mesa/main/multisample.c @@ -36,7 +36,7 @@ #include "state_tracker/st_context.h" #include "state_tracker/st_format.h" -#include "state_tracker/st_context.h" +#include "state_tracker/st_util.h" /** * Called via glSampleCoverageARB diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index c69f4e6..3e33c2b 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -41,25 +41,23 @@ #include "util/u_cpu_detect.h" -typedef void (*update_func_t)(struct st_context *st); - /* The list state update functions. */ -static update_func_t update_functions[ST_NUM_ATOMS]; +st_update_func_t st_update_functions[ST_NUM_ATOMS]; static void init_atoms_once(void) { -#define ST_STATE(FLAG, st_update) update_functions[FLAG##_INDEX] = st_update; +#define ST_STATE(FLAG, st_update) st_update_functions[FLAG##_INDEX] = st_update; #include "st_atom_list.h" #undef ST_STATE if (util_get_cpu_caps()->has_popcnt) - update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = st_update_array_with_popcnt; + st_update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = st_update_array_with_popcnt; } void st_init_atoms( struct st_context *st ) { - STATIC_ASSERT(ARRAY_SIZE(update_functions) <= 64); + STATIC_ASSERT(ARRAY_SIZE(st_update_functions) <= 64); static once_flag flag = ONCE_FLAG_INIT; call_once(&flag, init_atoms_once); @@ -69,31 +67,3 @@ void st_destroy_atoms( struct st_context *st ) { /* no-op */ } - -/*********************************************************************** - * Update all derived state: - */ - -void st_validate_state(struct st_context *st, uint64_t pipeline_state_mask) -{ - struct gl_context *ctx = st->ctx; - - /* Inactive states are shader states not used by shaders at the moment. */ - uint64_t dirty = ctx->NewDriverState & st->active_states & pipeline_state_mask; - if (!dirty) - return; - - ctx->NewDriverState &= ~dirty; - - uint32_t dirty_lo = dirty; - uint32_t dirty_hi = dirty >> 32; - - /* Update states. - * - * Don't use u_bit_scan64, it may be slower on 32-bit. - */ - while (dirty_lo) - update_functions[u_bit_scan(&dirty_lo)](st); - while (dirty_hi) - update_functions[32 + u_bit_scan(&dirty_hi)](st); -} diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 0f8063f..11bfcb0 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -35,6 +35,7 @@ #define ST_ATOM_H #include "util/glheader.h" +#include "main/mtypes.h" #ifdef __cplusplus extern "C" { @@ -50,7 +51,6 @@ struct cso_velems_state; void st_init_atoms( struct st_context *st ); void st_destroy_atoms( struct st_context *st ); -void st_validate_state(struct st_context *st, uint64_t pipeline_state_mask); void st_setup_arrays(struct st_context *st, @@ -183,6 +183,10 @@ enum { #define ST_ALL_STATES_MASK (ST_PIPELINE_RENDER_STATE_MASK | \ ST_PIPELINE_COMPUTE_STATE_MASK) +typedef void (*st_update_func_t)(struct st_context *st); + +extern st_update_func_t st_update_functions[ST_NUM_ATOMS]; + #ifdef __cplusplus } #endif diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 7d8e12a..a3a3858 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -633,10 +633,7 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, * for bitmap drawing uses no constants and the FS constants are * explicitly uploaded in the draw_bitmap_quad() function. */ - if (ctx->NewDriverState & st->active_states & - ~ST_NEW_CONSTANTS & ST_PIPELINE_RENDER_STATE_MASK) { - st_validate_state(st, ST_PIPELINE_META_STATE_MASK); - } + st_validate_state(st, ST_PIPELINE_META_STATE_MASK & ~ST_NEW_CONSTANTS); struct pipe_sampler_view *view = NULL; diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 244df25..1ccdda1 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -52,6 +52,7 @@ #include "st_draw.h" #include "st_program.h" #include "st_cb_rasterpos.h" +#include "st_util.h" #include "draw/draw_context.h" #include "draw/draw_pipe.h" #include "vbo/vbo.h" diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index d47fe46..bf198ad 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -85,9 +85,7 @@ prepare_draw(struct st_context *st, struct gl_context *ctx, uint64_t state_mask) st_invalidate_readpix_cache(st); /* Validate state. */ - if (ctx->NewDriverState & st->active_states & state_mask) { - st_validate_state(st, state_mask); - } + st_validate_state(st, state_mask); /* Pin threads regularly to the same Zen CCX that the main thread is * running on. The main thread can move between CCXs. diff --git a/src/mesa/state_tracker/st_util.h b/src/mesa/state_tracker/st_util.h index 32c098a..2fcbbf2 100644 --- a/src/mesa/state_tracker/st_util.h +++ b/src/mesa/state_tracker/st_util.h @@ -106,6 +106,30 @@ st_point_size_per_vertex(struct gl_context *ctx) return false; } +static inline void +st_validate_state(struct st_context *st, uint64_t pipeline_state_mask) +{ + struct gl_context *ctx = st->ctx; + + /* Inactive states are shader states not used by shaders at the moment. */ + uint64_t dirty = ctx->NewDriverState & st->active_states & pipeline_state_mask; + + if (dirty) { + ctx->NewDriverState &= ~dirty; + + uint32_t dirty_lo = dirty; + uint32_t dirty_hi = dirty >> 32; + + /* Update states. Don't use u_bit_scan64 because 64-bit ffs (x86 BSF) + * is slower on x86_64 and emulated on i386. + */ + while (dirty_lo) + st_update_functions[u_bit_scan(&dirty_lo)](st); + while (dirty_hi) + st_update_functions[32 + u_bit_scan(&dirty_hi)](st); + } +} + #ifdef __cplusplus } #endif -- 2.7.4